| 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: 774
|
|
|
taken my comments back.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 879
|
|
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: 339
|
|
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 opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50691
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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.
|
 |
 |
|
|
subject: ajax not working with jsp
|
|
|