Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with large request data using AJAX

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What on earth are you sending?

Be sure it is a POST.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a JSP issue, so moved to the HTML forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you get the post parameters of a normal form submission?

Eric
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my AJAX call:



This is my servlet code that is being called:


What am I missing?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be sure that it is properly encoded.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain what is required to make sure it is properly encoded?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you probably want to set



As Bear says Libraries/frameworks do this for you.

Eric
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it sounds like a good idea. What check do I do at the servlet before the response is fired?
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic