io.js
function (xhr, options, promise) {
            console.log(NAME, '_initXHR');
            var instance = this,
                url = options.url,
                method = options.method || GET,
                headers = options.headers || {}, // all request will get some headers
                async = !options.sync,
                data = options.data,
                reject = promise.reject,
                sendPayload;
            // xhr will be null in case of a CORS-request when no CORS is possible
            if (!xhr) {
                console.error(NAME, '_initXHR fails: '+ERROR_NO_XHR);
                reject(new Error(ERROR_NO_XHR));
                return;
            }
            console.log(NAME, '_initXHR succesfully created '+(xhr._isXHR2 ? 'XMLHttpRequest2' : (xhr._isXDR ? 'XDomainRequest' : 'XMLHttpRequest1'))+'-instance');

            // method-name should be in uppercase:
            method = method.toUpperCase();
            // in case of BODY-method: eliminate any data behind querystring:
            // else: append data-object behind querystring
            if (BODY_METHODS[method]) {
                url = url.split('?'); // now url is an array
                url = url[0]; // now url is a String again
            }
            else if (data && (headers[CONTENT_TYPE]!==MIME_BLOB)) {
                url += ((url.indexOf('?') > 0) ? '&' : '?') + instance._toQueryString(data);
            }

            xhr.open(method, url, async);
            // xhr.responseType = options.responseType || 'text';
            options.withCredentials && (xhr.withCredentials=true);


            // more initialisation might be needed by extended modules:
            instance._xhrInitList.each(
                function(fn) {
                    fn(xhr, promise, headers, method);
                }
            );

            if (BODY_METHODS[method] && data) {
                if (headers[CONTENT_TYPE]===MIME_BLOB) {
                    if (!xhr._isXDR) {
                        sendPayload = data;
                    }
                }
                else {
                    sendPayload = ((headers[CONTENT_TYPE]===MIME_JSON) || xhr._isXDR) ? JSON.stringify(data) : instance._toQueryString(data);
                }
            }
            // send the request:
            xhr.send(sendPayload);

            console.log(NAME, 'xhr send to '+url+' with method '+method);

            // now add xhr.abort() to the promise, so we can call from within the returned promise-instance
            promise.abort = function() {
                console.log(NAME, 'xhr aborted');
                reject(new Error(ABORTED));
                xhr._aborted = true; // must be set: IE9 won't allow to read anything on xhr after being aborted
                xhr.abort();
            };

            // in case synchronous transfer: force an xhr.onreadystatechange:
            async || xhr.onreadystatechange();
        }
function (xhr, options, promise) {
            console.log(NAME, '_initXHR');
            var instance = this,
                url = options.url,
                method = options.method || GET,
                headers = options.headers || {}, // all request will get some headers
                async = !options.sync,
                data = options.data,
                reject = promise.reject,
                sendPayload;
            // xhr will be null in case of a CORS-request when no CORS is possible
            if (!xhr) {
                console.error(NAME, '_initXHR fails: '+ERROR_NO_XHR);
                reject(new Error(ERROR_NO_XHR));
                return;
            }
            console.log(NAME, '_initXHR succesfully created '+(xhr._isXHR2 ? 'XMLHttpRequest2' : (xhr._isXDR ? 'XDomainRequest' : 'XMLHttpRequest1'))+'-instance');

            // method-name should be in uppercase:
            method = method.toUpperCase();
            // in case of BODY-method: eliminate any data behind querystring:
            // else: append data-object behind querystring
            if (BODY_METHODS[method]) {
                url = url.split('?'); // now url is an array
                url = url[0]; // now url is a String again
            }
            else if (data && (headers[CONTENT_TYPE]!==MIME_BLOB)) {
                url += ((url.indexOf('?') > 0) ? '&' : '?') + instance._toQueryString(data);
            }

            xhr.open(method, url, async);
            // xhr.responseType = options.responseType || 'text';
            options.withCredentials && (xhr.withCredentials=true);


            // more initialisation might be needed by extended modules:
            instance._xhrInitList.each(
                function(fn) {
                    fn(xhr, promise, headers, method);
                }
            );

            if (BODY_METHODS[method] && data) {
                if (headers[CONTENT_TYPE]===MIME_BLOB) {
                    if (!xhr._isXDR) {
                        sendPayload = data;
                    }
                }
                else {
                    sendPayload = ((headers[CONTENT_TYPE]===MIME_JSON) || xhr._isXDR) ? JSON.stringify(data) : instance._toQueryString(data);
                }
            }
            // send the request:
            xhr.send(sendPayload);

            console.log(NAME, 'xhr send to '+url+' with method '+method);

            // now add xhr.abort() to the promise, so we can call from within the returned promise-instance
            promise.abort = function() {
                console.log(NAME, 'xhr aborted');
                reject(new Error(ABORTED));
                xhr._aborted = true; // must be set: IE9 won't allow to read anything on xhr after being aborted
                xhr.abort();
            };

            // in case synchronous transfer: force an xhr.onreadystatechange:
            async || xhr.onreadystatechange();
        }
function ( xhr , options , promise ) { console . log ( NAME , '_initXHR' ) ; var instance = this , url = options . url , method = options . method || GET , headers = options . headers || { } , // all request will get some headers async = ! options . sync , data = options . data , reject = promise . reject , sendPayload ; // xhr will be null in case of a CORS-request when no CORS is possible if ( ! xhr ) { console . error ( NAME , '_initXHR fails: ' + ERROR_NO_XHR ) ; reject ( new Error ( ERROR_NO_XHR ) ) ; return ; } console . log ( NAME , '_initXHR succesfully created ' + ( xhr . _isXHR2 ? 'XMLHttpRequest2' : ( xhr . _isXDR ? 'XDomainRequest' : 'XMLHttpRequest1' ) ) + '-instance' ) ; // method-name should be in uppercase: method = method . toUpperCase ( ) ; // in case of BODY-method: eliminate any data behind querystring: // else: append data-object behind querystring if ( BODY_METHODS [ method ] ) { url = url . split ( '?' ) ; // now url is an array url = url [ 0 ] ; // now url is a String again } else if ( data && ( headers [ CONTENT_TYPE ] !== MIME_BLOB ) ) { url += ( ( url . indexOf ( '?' ) > 0 ) ? '&' : '?' ) + instance . _toQueryString ( data ) ; } xhr . open ( method , url , async ) ; // xhr.responseType = options.responseType || 'text'; options . withCredentials && ( xhr . withCredentials = true ) ; // more initialisation might be needed by extended modules: instance . _xhrInitList . each ( function ( fn ) { fn ( xhr , promise , headers , method ) ; } ) ; if ( BODY_METHODS [ method ] && data ) { if ( headers [ CONTENT_TYPE ] === MIME_BLOB ) { if ( ! xhr . _isXDR ) { sendPayload = data ; } } else { sendPayload = ( ( headers [ CONTENT_TYPE ] === MIME_JSON ) || xhr . _isXDR ) ? JSON . stringify ( data ) : instance . _toQueryString ( data ) ; } } // send the request: xhr . send ( sendPayload ) ; console . log ( NAME , 'xhr send to ' + url + ' with method ' + method ) ; // now add xhr.abort() to the promise, so we can call from within the returned promise-instance promise . abort = function ( ) { console . log ( NAME , 'xhr aborted' ) ; reject ( new Error ( ABORTED ) ) ; xhr . _aborted = true ; // must be set: IE9 won't allow to read anything on xhr after being aborted xhr . abort ( ) ; } ; // in case synchronous transfer: force an xhr.onreadystatechange: async || xhr . onreadystatechange ( ) ; }
Initializes the xhr-instance, based on the config-params.
This method is the standard way of doing xhr-requests without processing streams.

@method _initXHR
@param xhr {Object} xhr-instance
@param options {Object}
@param [options.url] {String} The url to which the request is sent.
@param [options.method='GET'] {String} The HTTP method to use.
can be ignored, even if streams are used --> the returned Promise will always hold all data
@param [options.sync=false] {boolean} By default, all requests are sent asynchronously. To send synchronous requests, set to true.
This feature only works in the browser: nodejs will always perform asynchronous requests.
@param [options.data] {Object} Data to be sent to the server, either to be used by `query-params` or `body`.
@param [options.headers] {Object} HTTP request headers.
@param [options.responseType] {String} Force the response type.
@param [options.timeout=3000] {number} to timeout the request, leading into a rejected Promise.
@param [options.withCredentials=false] {boolean} Whether or not to send credentials on the request.
@param fulfill {Function} reference to xhr-promise's fulfill-function
@param reject {Function} reference to xhr-promise's reject-function
@param promise {Promise} the xhr-promise which will be extended with the `abort()`-method
@private
Initializes the xhr - instance based on the config - params . This method is the standard way of doing xhr - requests without processing streams .