forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXHRLoader.js
More file actions
38 lines (26 loc) · 1.1 KB
/
XHRLoader.js
File metadata and controls
38 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;