index.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  4. <head>
  5. <title>Javascript Example</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  7. <script src="prototype.js" type="text/javascript"></script>
  8. </head>
  9. <body>
  10. <h1>Fetching object from server</h1>
  11. <div id="list">
  12. Wait...<br/>
  13. <noscript><p>Switch on Javascript!</p></noscript>
  14. </div>
  15. <script type="text/javascript">
  16. <!--
  17. function pollJSON() {
  18. new Ajax.Request('/json',
  19. {
  20. method: 'get',
  21. onSuccess: function(transport) {
  22. var response = transport.responseText || "no response text";
  23. response = eval("(" + response + ")");
  24. var text = "";
  25. for (var k in response) {
  26. text = text + "<b>" + k + "</b>: " + response[k] + "<br/>"
  27. }
  28. $("list").update(text);
  29. },
  30. onFailure: function() { alert('Something went wrong...') }
  31. });
  32. }
  33. new PeriodicalExecuter(pollJSON, 1);
  34. -->
  35. </script>
  36. </body>
  37. </html>