aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Issue with large request data using AJAX Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Issue with large request data using AJAX" Watch "Issue with large request data using AJAX" New topic
Author

Issue with large request data using AJAX

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
My AJAX process is failing when the parameter I am sending to the servlet has more than 1876 or so characters. Is there a solution to this problem? I need a way to send very large(20,000+) characters.
[ October 17, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61237
    
  66

What on earth are you sending?

Be sure it is a POST.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
The app I am working on is a cross tabular matrix(A Buyer Furnished Equipement list for Aircraft Seat Customer). All the matrix items are stored in a database. I use java to export this matrix out to Excel for presentation and printing.
So far the design of the app is thus(remember I am very new a web design so I can really use some help)
1. A form for header info input
next
2. A form for a single sub-level dash number
next
3. A form for x-axis list-seat assembly numbers- and qty of each(there can be three different classes of seats)
next
4. A form for y-axis list-details that go into the seat assemblies and qty of each

Is there a way I can send you a pdf file of finished product?

This is part of my AJAX code:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61237
    
  66

Not a JSP issue, so moved to the HTML forum.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61237
    
  66

Your problem is that you are trying to send POST information on the URL as a query string. Send the data in the request body. Be sure that it is properly encoded.

It looks like you are using raw Ajax. Not recommended. I strongly advise you to adopt one of jQuery or Prototype for your Ajax needs. Either will make it much easier to make Ajax requests correctly.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
As Bear said, you are still using a get since you are appending the values to the url. The post parameters belong inside the send without the "?"

....send("foo=bar&man=beer");

The best bet is to use a library to do Ajax calls since they handle all of the little browser quirks.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
If I send the string in the send method of the AJAX code how do I get this value at the servlet? arg0.getParameter() does not retreive any thing.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
How would you get the post parameters of a normal form submission?

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
My code usually looks like this:



But this only works if I use ?detaillitstring=" + detailListString in my URL string. If I place it in the send method the value of detailList is empty.

Again thanks for helping.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you looked at my example I posted above, you can problably see what your issue is. I will post it again.

...send("foo=bar&man=beer");

Notice what is in front of foo, and than look at what you posted.

Next thing, get Firefox if you do not have it. Download firebug (http://www.getFirebug.com) and enable the XMLHttpRequest monitoring. You can see what is happening.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
This is my AJAX call:



This is my servlet code that is being called:


What am I missing?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61237
    
  66

Be sure that it is properly encoded.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Can you explain what is required to make sure it is properly encoded?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61237
    
  66

Investigate the encodeURI() and encodeURIComponent() methods.

All this would be moot if you'd take the suggestion of using jQuery or Prototype for Ajax.

Do not take this suggestion lightly. If you look through the history of my posts, you will see that I rarely recommend the adoption of some framework or library unless there's a very clear gain. In this case, using either of Prototype's Ajax.Request or jQuery's $.post() methods is a major gain. They will handle all the Ajax low-level plumbing that makes Ajax a pain to use and that is easy to get wrong (as you are discovering).

Even if you don't use any of the other (very useful) parts of these libraries, using them to make Ajax calls is worth their download.

At this point in time, I delare it madness to use straight-up Ajax.
[ October 17, 2007: Message edited by: Bear Bibeault ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Also you probably want to set



As Bear says Libraries/frameworks do this for you.

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Ok, thanks to you I got the jQuery library loaded and using it has fixed my post issues invloving large data strings. But one more issue.

I am using the AJAX to fire a servlet which fires code to create a PDF file of an excel spreadsheet that displays my data(breath).

When the code is ran a hyperlink appears on the firing page linked to the PDF file. How can I get this appearing link to wait until the file is ready to be opened? When using the raw AJAX I depended on the readystate and status values.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
The JQuery code is using the readystate values just like you were. It is doing all of that dirty work for you.

What is the problem? The server returning the link before the PDF is fully generated?

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Yes, if I click the link imedeately after the link appears I get a blank page. If I wait about 10 seconds every thing is correct. This tells me the file has not finished being processed before the link appears.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Any reason why you are not running the process on the server and hold the Response Until you get confirmation the file was built?

Eric
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
No, it sounds like a good idea. What check do I do at the servlet before the response is fired?
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Wait, my servlet does not have any response line of code. It only fires the java class that creates the pdf file.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1446
    
    1
Can anyone elaborate on the suggestion that was made concerning the response being held until the servlet is finished before the form displays the link to the created file?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Issue with large request data using AJAX