File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes ajax not working with jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "ajax not working with jsp" Watch "ajax not working with jsp" New topic
Author

ajax not working with jsp

Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
Dear friends,

Kindly consider the following function:



And the following jsp file which is used for saving in database only



However, the ajax is not working and the data is not getting saved and i get the status as 0. Please help.


Anand Shrivastava
SCJA
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

taken my comments back.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Looks ok to me at a glance.

That java code should really be in a servlet rather than a jsp.

Are you able to tell if your JSP url is being invoked (use a net monitor in your browser, or a tool like Fiddler)
Are there any javascript errors in your console?

Are you perchance using firefox? http://stackoverflow.com/questions/3881359/xmlhttprequest-returns-status-of-0-in-firefox-3-6-10-and-up-from-cross-origin-re
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Does the JSP file get executed at all? If yes, does it return anything? Perhaps the content type needs to be set correctly in the JSP code. At the following link you can find a complete AJAX example, using a JSP file: http://koenaerts.ca/a-complete-ajax-example/
The example uses a POST rather than a GET to send the request, which I would recommend because the GET URL has limitations on how long it can be, something like 1024 characters or something like it, I can't remember exactly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61198
    
  66

Koen Aerts wrote:The example uses a POST rather than a GET to send the request, which I would recommend because the GET URL has limitations on how long it can be

This is not the proper criteria on which to determine whether to use a GET or a POST. These methods have clearly defined roles within HTTP.

GET should be used for idempotent requests used to fetch a resource. POST for operations that are potentially non-idempotent.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anand Shrivastava
Ranch Hand

Joined: Jul 22, 2007
Posts: 125
Dear friends,

Thanks a lot. I figured it out.
The URL is malformed
It was


whereas, "&" should be used in place of "?" and it should be



Thanks a lot friends.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ajax not working with jsp