Simulate graph states in the browser
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var api = {};
  2. api.poll = function() {
  3. var xmlhttp = new XMLHttpRequest();
  4. xmlhttp.onreadystatechange = function() {
  5. if (xmlhttp.readyState == XMLHttpRequest.DONE) {
  6. if (xmlhttp.status == 200) {
  7. api.update(xmlhttp.responseText);
  8. }
  9. }
  10. };
  11. // Send the request
  12. xmlhttp.open("GET", "/graph", true);
  13. xmlhttp.send();
  14. };
  15. api.update = function(s) {
  16. json = JSON.parse(s);
  17. graph.update(json);
  18. }
  19. api.edit = function(edit) {
  20. var xmlhttp = new XMLHttpRequest();
  21. xmlhttp.onreadystatechange = function() {
  22. if (xmlhttp.readyState == XMLHttpRequest.DONE) {
  23. if (xmlhttp.status == 200) {
  24. api.update(xmlhttp.responseText);
  25. }
  26. }
  27. };
  28. // Send the request
  29. xmlhttp.open("POST", "/edit", true);
  30. xmlhttp.setRequestHeader("Content-Type", "application/json");
  31. xmlhttp.send(JSON.stringify(edit));
  32. }
  33. // Launch the polling loop
  34. setInterval(api.poll, 1000);