- Create a new request
- Prepare the request
- Set the
onloadcallback. The callback can access the response by referencingthis.responseText. - Send the request
var xhr = new XMLHttpRequest();
xhr.open("GET", "/fancy.json", true);
xhr.onload = function () {
json = JSON.parse(this.responseText);
...
};
xhr.send();- Create a new image object
- Set the
onloadcallback. In the callback the image object can be referenced bythis. - Set image
srcurl
var image = new Image();
image.onload = function() { ... };
image.src = "/fancy-image.png";```