mirror of
https://github.com/photonstorm/phaser
synced 2024-12-18 17:16:03 +00:00
35 lines
916 B
JavaScript
35 lines
916 B
JavaScript
|
var MergeXHRSettings = require('./MergeXHRSettings');
|
||
|
|
||
|
var XHRLoader = function (file, globalXHRSettings)
|
||
|
{
|
||
|
var config = MergeXHRSettings(globalXHRSettings, file.xhr);
|
||
|
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
|
||
|
xhr.open('GET', file.src, config.async, config.user, config.password);
|
||
|
|
||
|
xhr.responseType = file.xhr.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(xhr);
|
||
|
xhr.onerror = file.onError(xhr);
|
||
|
|
||
|
xhr.send();
|
||
|
|
||
|
return xhr;
|
||
|
};
|
||
|
|
||
|
module.exports = XHRLoader;
|