• 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 XmlHttpRequest object

 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a page where i will be displaying the list of records from DB ..an i need to refresh this page after some interval depending on certain conditions . While doing this can i get the new data from the backend and can i access that using this XmlHttpRequest's response

Its like my backend will return me the refreshed List and i need to update the page with these results

Can i achive that with out refreshing the page by using this XmlHttpRequest Object ??
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is possible to do this with the XMLHttpRequest Object.

You can use JavaScript to set up a timer that executes your function that initiates the XMLHttpRequest object.

Example would be
var timer = setInterval("LoadXMLDoc()",30000);

Then whenyou return the page from the server you can either format the HTML on the server or make an XML document and format it on the client.

I am going to work on an example code for my blog tomorrow that whows some basic interaction with the server.

Eric
 
sreenath reddy
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi eric

DO u mean to say get the HTML code rendered at the backend itself . Is this a good practice to build the HTML code in the backend

and what is this concept of taking the data from XML to the client ??

Can u share some links for enhancing the knowledge on these XmlHttpRequest objects
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two ways of doing this:

You can build the html on the server or you can build an XML document on the server and have the JavaScript build the html code.

Either way works. Some people perfer to use the server side to do it since they do not know JavaScript. Others perfer JavaScript since you can use DOM to build the elements.

The difference between builing the two methods are.

Building the html code, you need to use the responseText property of the XMLHttpRequest Object. With XML, we want to use the responseXML property.

If you return a document that is not XML, then you can not use JavaScript XML DOM methods to access the elements.

Some people sayy building the HTML on the server eliminates the extra looping on the client. It is true and I work with book concepts in my book AJAX in Action. I know you can not wait to November to see the code so look here: http://www.fiftyfoureleven.com/resources/programming/xmlhttprequest/examples

I am also trying to put together an example on my blog with a server interaction that works with a timeout.

Eric
 
Not looking good. I think this might be the end. Wait! Is that a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic