Update Content Every X-seconds with Ajax Cals November 2, 2011Posted by Tournas Dimitrios in JQuery.
setInterval( "alert('Hello')", 5000 );
Now consider we want to update the contents of an div-box every 10 seconds . The following code will query a PHP enabled server that will respond with the time .
JQuery has an AJAX function called “load”, which accepts three parameters ( only the first is mandatory ) :
- the page you want to load (url) ,
- data you want to send (POST) — optional
- a callback function — optional .
Our example requests data from a remote server , so only the first parameter is used . The server responds with a plain-text message which is appended to the ” #box ” tag . In a real world application , the server would carry out a web-service and respond in XML , JSON or JSONP format .