File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes using ajax for http get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "using ajax for http get " Watch "using ajax for http get " New topic
Author

using ajax for http get

harsha galla
Greenhorn

Joined: Sep 24, 2008
Posts: 18
Iam new to using Ajax and I have few doubts. What actually does .responsetext method on the XMLHttp Object retreive in case i use it to Http Get to a servlet. Is it possible I can send a message from servlet when get is done from a servlet as a responsetext, if so how can it be done.Please explain in detail.

Thanks in advance..
[ October 21, 2008: Message edited by: harsha galla ]
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 357
Say your servlet returns a well formed XML document. When the readyState property of the XMLHttpRequest object is 4 (i.e. DONE) responseXML will be a DOM Document of the XML and responseText will have a DOMString of the XML.

When your servlet returns some old text and readyState is 4 responseXML will be null but responseText will have the text as a DOMString.

How these two properties behave is influenced by a few more factors and you can read about them from the w3c XMLHttpRequest working draft .
harsha galla
Greenhorn

Joined: Sep 24, 2008
Posts: 18
Suppose when i click on the submit button some javascript handles the action, creates xmlhttp object and forwards to a servlet which then does some registration stuff. The servlet should then throw some message on success of registration or an exception which should be handled by the xmlhttp object and displayed dynamically on the registration page itself..
Gamini Sirisena
Ranch Hand

Joined: Aug 05, 2008
Posts: 357
You'll need the servlet to handle the Exception and send some
error code back to the XMLHttpRequest and handle it that way.

It seems obvious that you can't propagate Java exceptions
through XHR. However you could send the Exception stack trace back,
but it is probably not a good idea to show this to the user.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using ajax for http get