test.html 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:wb="http://open.weibo.com/wb" style="overflow: hidden;">
  3. <head>
  4. <script>
  5. function poll() {
  6. var start = 0;
  7. var time = null;
  8. var xhr = new XMLHttpRequest();
  9. var data = "";
  10. xhr.open("POST", "http://127.0.0.1:3000", true);
  11. xhr.onreadystatechange = function () {
  12. if (xhr.readyState == 3 && xhr.status == 200) {
  13. clearTimeout(time);
  14. var len = xhr.responseText.length;
  15. data += xhr.responseText.substring(start, len);
  16. start = len;
  17. time = setTimeout(function () {
  18. clearTimeout(time);
  19. data = "";
  20. }, 100);
  21. }
  22. }
  23. xhr.onerror = function (err) {
  24. console.log(err);
  25. }
  26. xhr.send();
  27. }
  28. window.onload = function () {
  29. poll()
  30. }
  31. </script>
  32. </head>
  33. <body>
  34. </body>
  35. </html>