wood burning stoves 2.0*
The moose likes Servlets and the fly likes jQuery Ajax unable to read streamed html from a servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jQuery Ajax unable to read streamed html from a servlet." Watch "jQuery Ajax unable to read streamed html from a servlet." New topic
Author

jQuery Ajax unable to read streamed html from a servlet.

Rick Perry
Greenhorn

Joined: Jun 10, 2011
Posts: 2
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

Joined: Jun 10, 2011
Posts: 2
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

Joined: Jan 10, 2002
Posts: 60766
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jQuery Ajax unable to read streamed html from a servlet.
 
Similar Threads
Deleting multiple records using jQuery-ajax at a time.
jquery - ajax call to another site and parse result
Calling a new JSP form a Spring Controller using Ajax
Trying to use AJAX to call a servlet
Can you post data from textfields to a URL without having a <form>