Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery Ajax unable to read streamed html from a servlet.

 
Rick Perry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running Tomcat 5.5.23/Firefox 4.0 with Firebug. I've a very simple problem and it's beyond perplexing at this point. I've a static html page that I open (as in File -> Open) using the browser (it's not even behind a web server). That static html file looks like below:



I've the following servlet running at port 80 (Tomcat).




When I click the button on html page, I can see the ajax request being sent using the Firebug (XHR panel). I get a Http 200 status, the response size seems in line with the string being printed... the Ajax call is successful!, because it executes the success: function. however.. here's the kicker!.. the "data" field is empty.. the alert box in the success function alert nothing I was hoping to see"<h3>foobar</h3>"..

I had the ajax url as "http://localhost", but that extra DNS lookup slows me down by 7 ms.
Also there don't seem to be any http proxy/networking issues. The request is getting to the servlet.
The servlet itself works fine (in the browser.. http://localhost prints "foobar")

What gives? This seems like jquery-servlet 101 stuff.. am I missing something...?
 
Rick Perry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the problem was that the html snippet that I opened as a File in a browser.. needs to be actually be served up behind a webserver for the Ajax response to be handled.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick Perry wrote:that I open (as in File -> Open) using the browser (it's not even behind a web server).

And that is the problem. Ajax will not work properly unless served from a server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic