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

Ajax with jQuery and servlets

 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good evening,
I'm trying to get a response from an Ajax call using jQuery and servlets, but somehow I always get an error.

jQuery code:


Servlet code:


If I type the servlet url I get the "You're in!" message, but when I try to use jQuery routine I get "Error requesting page http://localhost:8080/investking/servlet/login".
Does anyone know how could I do it? Or at least a better way to communicate jQuery with servlets?

Many thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you get the same issue with:

?
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I also get "Error requesting page /investking/servlet/login". I really don't know where to search, I've also tried with JSON, but the problem should be in the request, not in the format.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, that sounds really odd and unrelated to jQuery. At this point I'd run the page under Firefox with Firebug installed to see what other information can be gathered about the nature of the error. Firebug is absolutely essential to diagnosing Ajax problems.
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uhm, I'm running Firefox 3.0b5 under Ubuntu and Firebug is not ready yet for that version. I've tried to install Firefox 2 but I can't make it work.
I suppose I'll have to try with another library... any suggestion?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another library will yield the same results. I'm pretty sure that this is an Ajax issue not a jQuery issue.

Do you have no tools at your disposal that will show you the request and response details? TamperData? other Ubuntu tools?

Btw, just to be sure about things:

URL you typed into the browser:
http://localhost:8080/investking/servlet/login

URL on Ajax request:
/investking/servlet/login

And the page containing the Ajax request is part of the same web app. Correct?
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow Bear, that TamperData is amazing!
When I press on 'Details' on the first message I can see that the servlet sends back the "You're in!" message, but for some reason seems that jQuery takes it as an error.
That first message comes with the 'LOAD_BACKGROUND' flag, but just after it comes another one from http://localhost:8080/investking/ with the load flags 'LOAD_DOCUMENT_URI' and 'LOAD_INITIAL_DOCUMENT_URI'. This second message makes the page reload.
Do you know why it happens?
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I forgot to tell you that you're right: the URL I typed into the browser was http://localhost:8080/investking/servlet/login and the URL on Ajax request is /investking/servlet/login. And the page with the request is in the same webapp as the servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, that's really odd. I've never seen jQuery choke on a valid response. What version of jQuery are you using? I'll see if I can reproduce your issue.
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using jQuery 1.2.3, but don't worry about it. You've already done a lot to help me, I'll try with other jQuery versions and JavaScript libraries.
Thank you indeed for your help!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do find it's an issue with jQuery, please let me know so I can file an appropriate bug report.
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't know why it didn't work, but now I'm using the jQuery Forms plugin and it's working like a charm
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64843
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Form plugin rocks! I especially like the way it can take a "normal" form and Ajax-ify it for you with a single line of JS.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.getfirebug.com/releases/

Install the 1.2 Alpha and it will work, enough. I had the same issues trying to install FF2 and the FireBug beta is a POS. Alpha seems to be working for me though.
 
Derrick Shoemake
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry this is late, but if you type the URL into the browser it should run the doGet method of a servlet, but it you submit a form, it should be running the doPost method. A simple call to the doGet from the doPost should fix this problem.



EDIT:

Opps, I thought I read it as $.post instead of $.get, I should learn to read one of these days...nevermind
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say you are late, over a year late.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic