• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Ajax with jQuery and servlets

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you get the same issue with:

?
 
Dani Thorp
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say you are late, over a year late.

Eric
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic