var api = {}; api.poll = function() { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == XMLHttpRequest.DONE) { if (xmlhttp.status == 200) { api.update(xmlhttp.responseText); } } }; // Send the request xmlhttp.open("GET", window.location.href+"/graph", true); xmlhttp.send(); }; api.update = function(s) { json = JSON.parse(s); materials.qubit.size = big.checked ? 2 : 0.4; graph.update(json); } api.edit = function(edit) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == XMLHttpRequest.DONE) { if (xmlhttp.status == 200) { api.update(xmlhttp.responseText); } } }; // Send the request xmlhttp.open("POST", window.location.href+"/edit", true); xmlhttp.setRequestHeader("Content-Type", "application/json"); xmlhttp.send(JSON.stringify(edit)); } // Launch the polling loop setInterval(api.poll, 1000);