Skip to content

Instantly share code, notes, and snippets.

View TiMladenov's full-sized avatar

Tihomir Mladenov TiMladenov

View GitHub Profile
@santisbon
santisbon / XMLHttpRequestLoadImagePromise.js
Last active August 16, 2023 19:00
Using XMLHttpRequest to load an image in a #javascript #promise. Based on Mozilla Developer Network documentation.
/*jslint devel: true, browser: true, es5: true */
/*global Promise */
function imgLoad(url) {
'use strict';
// Create new promise with the Promise() constructor;
// This has as its argument a function with two parameters, resolve and reject
return new Promise(function (resolve, reject) {
// Standard XHR to load an image
var request = new XMLHttpRequest();