main.js 883 B

1234567891011121314151617181920212223242526272829303132
  1. // Non-blocking http request runs asynchronously.
  2. var request = new Atomic.WebRequest("GET", "https://httpbin.org/get", 0);
  3. // Accumulate the data into this var.
  4. var data = "";
  5. // Listen for the "download_chunk" event to see when we have data.
  6. // Note that this event is not available on all platforms.
  7. request.subscribeToEvent("download_chunk", function (event) {
  8. data += event.download.readString();
  9. });
  10. // Listen for the "complete" event to see when the response is complete.
  11. request.subscribeToEvent("complete", function (event) {
  12. if (event.error) {
  13. // When something goes wrong, print the error, then return.
  14. console.log("Error:\n" + event.error);
  15. return;
  16. }
  17. // We're done, so print the data.
  18. console.log("Downloaded:\n" + data);
  19. });
  20. // Nothing happens until send() is called.
  21. console.log("Sending . . .\n");
  22. request.send();