Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You want two files. your client file (index.js) and your php file (poll.php)
- your js (client file) will use XMLHttpRequest's to request the page poll.php from the server.
- poll.php will output ONLY the html you want to send to the client.
- Below is untested client code you can look over.
- index.js ::
- function getStuff(url, callback) {
- var xhr = new XMLHttpRequest();
- xhr.open('GET', url);
- xhr.onload = callback;
- xhr.send();
- }
- function swapContent(content) {
- if( content && content.responseText ) {
- while(container.hasChildNodes()) {
- container.removeChild(container.firstchild);
- }
- container.innerHTML = content.responseText;
- }
- getStuff(url, function() {
- setTimeout(swapContent, 3000);
- });
- }
- var url = '';
- var container = ..;
- swapContent();
- poll.php ::
- w/e you had to output the new HTML for the client.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement