• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using ajax for http get

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tell me how it all turns out. Here is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic