Advertisement
Guest User

Untitled

a guest
May 13th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. You want two files. your client file (index.js) and your php file (poll.php)
  2.  
  3. your js (client file) will use XMLHttpRequest's to request the page poll.php from the server.
  4.  
  5. poll.php will output ONLY the html you want to send to the client.
  6.  
  7. Below is untested client code you can look over.
  8.  
  9. index.js ::
  10. function getStuff(url, callback) {
  11. var xhr = new XMLHttpRequest();
  12. xhr.open('GET', url);
  13. xhr.onload = callback;
  14. xhr.send();
  15. }
  16.  
  17. function swapContent(content) {
  18. if( content && content.responseText ) {
  19. while(container.hasChildNodes()) {
  20. container.removeChild(container.firstchild);
  21. }
  22. container.innerHTML = content.responseText;
  23. }
  24. getStuff(url, function() {
  25. setTimeout(swapContent, 3000);
  26. });
  27. }
  28.  
  29. var url = '';
  30. var container = ..;
  31. swapContent();
  32.  
  33. poll.php ::
  34.  
  35. w/e you had to output the new HTML for the client.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement