Advertisement
Guest User

jake2

a guest
Apr 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. window.onload=function(){
  2. var canvas= document.getElementById('myCanvas'); // left it here for you
  3. console.log(" client loaded");
  4. canvas.addEventListener('mousedown',askForData,false);
  5. var arrayBuffer = "";
  6. var id = setInterval(runLoop,10);
  7. function runLoop(){
  8. var ctx=canvas.getContext('2d');
  9. ctx.fillStyle = "green";
  10. ctx.fillRect(0,0,canvas.width,canvas.height);
  11. if (arrayBuffer === ""){
  12. ctx.fillStyle = "black";
  13. ctx.fillText("No Message Yet",30,30);
  14. }
  15. else {
  16. ctx.fillStyle="black";
  17. ctx.fillText(arrayBuffer.name,30,30);}
  18. }
  19.  
  20. function askForData(){
  21. function doSomethingWithData(){
  22. var tempBuffer = dataRequest.responseText;
  23. console.log(tempBuffer);
  24. arrayBuffer = JSON.parse(tempBuffer); // turns my data into accessible data
  25. console.log(arrayBuffer);
  26. }
  27. var dataRequest = new XMLHttpRequest();
  28. dataRequest.addEventListener('load',doSomethingWithData);
  29. dataRequest.open('GET','/GetSomeData');
  30. dataRequest.send();
  31. }
  32. } // end of window onload - never delete this one!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement