phaser/v3/src/loader/XHRLoader.js

38 lines
1.1 KiB
JavaScript

var MergeXHRSettings = require('./MergeXHRSettings');
var XHRLoader = function (file, globalXHRSettings)
{
var config = MergeXHRSettings(globalXHRSettings, file.xhrSettings);
var xhr = new XMLHttpRequest();
xhr.open('GET', file.src, config.async, config.user, config.password);
xhr.responseType = file.xhrSettings.responseType;
xhr.timeout = config.timeout;
if (config.header && config.headerValue)
{
xhr.setRequestHeader(config.header, config.headerValue);
}
if (config.overrideMimeType)
{
xhr.overrideMimeType(config.overrideMimeType);
}
// After a successful request, the xhr.response property will contain the requested data as a DOMString, ArrayBuffer, Blob, or Document (depending on what was set for responseType.)
xhr.onload = file.onLoad.bind(file);
xhr.onerror = file.onError.bind(file);
xhr.onprogress = file.onProgress.bind(file);
// This is the only standard method, the ones above are browser additions (maybe not universal?)
// xhr.onreadystatechange
xhr.send();
return xhr;
};
module.exports = XHRLoader;