An AJAX request (XMLHttpRequest) is probably the way to go.
I have a very simple example of an XMLHttpRequest (with Java as the backend) here: https://stackoverflow.com/a/18028943/1468130
You could recreate a backend to receive HTTP GET requests in any other server-side language. Just echo back whatever data you retrieved, and xmlhttp.onload()
will catch it.
Depending on how complex your data is, you may want to find a JSON library for your server-side language of choice, and serialize your data to JSON before echoing it back to your JS. Then you can use JavaScript's JSON.parse()
method to convert your server data to an object that can easily be used by the client script.
If you are using jQuery, it handles AJAX very smoothly, and using $.ajax()
would probably be easier than plain-old XMLHttpRequest.
http://api.jquery.com/jQuery.ajax/ (There are examples throughout this page, mostly-concentrated at the bottom.)
It really annoys me how complicated so many of the AJAX tutorials are. At least with jQuery, it's pretty easy.
Basically, you just need to ask a script for something (initiate the request, send url parameters), and wait for the script to give you something back (trigger your onload()
or jqxhr.done()
functions, supplying those functions with a data
parameter).
For your other questions:
- Use JavaScript's
setTimeout()
orsetInterval()
to initiate an AJAX request every 600000 milliseconds. In the request'sonload
callback, handle your data and update the page appropriately. - The response will be asynchronous.
- This isn't a socket.
- "Pushing" probably isn't the way to go in this case.