2016-11-30 00:18:34 +00:00
var MergeXHRSettings = require ( './MergeXHRSettings' ) ;
var XHRLoader = function ( file , globalXHRSettings )
{
2016-12-01 12:50:58 +00:00
var config = MergeXHRSettings ( globalXHRSettings , file . xhrSettings ) ;
2016-11-30 00:18:34 +00:00
var xhr = new XMLHttpRequest ( ) ;
xhr . open ( 'GET' , file . src , config . async , config . user , config . password ) ;
2016-12-01 12:50:58 +00:00
xhr . responseType = file . xhrSettings . responseType ;
2016-11-30 00:18:34 +00:00
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.)
2016-12-01 12:50:58 +00:00
xhr . onload = file . onLoad . bind ( file ) ;
xhr . onerror = file . onError . bind ( file ) ;
xhr . onprogress = file . onProgress . bind ( file ) ;
2016-11-30 17:16:45 +00:00
// This is the only standard method, the ones above are browser additions (maybe not universal?)
// xhr.onreadystatechange
2016-11-30 00:18:34 +00:00
xhr . send ( ) ;
return xhr ;
} ;
module . exports = XHRLoader ;