Skip to content

Instantly share code, notes, and snippets.

@korya
Last active December 27, 2015 18:18
Show Gist options
  • Select an option

  • Save korya/7368277 to your computer and use it in GitHub Desktop.

Select an option

Save korya/7368277 to your computer and use it in GitHub Desktop.
Notes for HTML5 Game Development by Udacity

XMLHttpRequest

  1. Create a new request
  2. Prepare the request
  3. Set the onload callback. The callback can access the response by referencing this.responseText.
  4. Send the request
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "/fancy.json", true);
  xhr.onload = function () {
    json = JSON.parse(this.responseText);
    ...
  };
  xhr.send();

Image

  1. Create a new image object
  2. Set the onload callback. In the callback the image object can be referenced by this.
  3. Set image src url
  var  image = new Image();
  image.onload = function() { ... };
  image.src = "/fancy-image.png";```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment