300x250 AD TOP

Text Widget

Total Pageviews

Subscribe us

Contact Us

Name

Email *

Message *

Powered by Blogger.

You can also receive Free Email Updates:

Popular Posts

Followers

Tuesday, 10 July 2012

Tagged under: , ,

Auto Refresh a Web Page using AJAX

AJAX is nothing but Asynchronous JavaScript and XML. It is not a new programming language, but a new way to use the existing standards. It is the art of exchanging data with a server, and updating parts of a web page without reloading the whole page!!

Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. JavaScript and XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

 Using JavaScript for periodically refreshing a page can be quite annoying, as the entire page reloads time to time. Hence, a better option would be to use AJAX.
Include the following code in the <head> section of the page....



The section now refreshes after every 20 seconds. You can change the 20000 value to suite your requirements.
You can remove the ".fadeOut('slow')" and ".fadeIn(Slow)" parts if you want the page to be refreshed unnoticed.

Now, whichever section you want to be refreshed, must be included within the <div id="loaddiv"> tags as follows:



You are now done!! Enjoy as your page refreshes without you noticing!!

2 comments:

  1. Actually, I'm not that well versed with jsp. But I dont think there can be any problem here....The content within the loaddiv tag is getting refreshed...you can test it by using a session variable within the load tag and incrementing it...the incremented value should be displayed after 5 sec, and this goes on. This is not a normal refresh, but refresh using ajax....so, you would not be able to see whether the page is being refreshed in your example.

    ReplyDelete
  2. Ok i'll try it out & let u know!!!!
    & keep up the good work!!!!
    God bless u!!!!!!!
    Thanks for ur reply!!!!!

    ReplyDelete