2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-27 14:47:43 +03:00

Fixing IE8 support by bringing back onreadystatechange

Fixes #241
This commit is contained in:
Colin Timmermans
2016-02-25 10:53:12 +01:00
parent 235f34312c
commit ca0617061e
+14 -3
View File
@@ -16,11 +16,15 @@ module.exports = function xhrAdapter(resolve, reject, config) {
}
var request = new XMLHttpRequest();
var loadEvent = 'onreadystatechange';
var xDomain = false;
// For IE 8/9 CORS support
// Only supports POST and GET calls and doesn't returns the response headers.
if (window.XDomainRequest && !('withCredentials' in request) && !isURLSameOrigin(config.url)) {
request = new window.XDomainRequest();
loadEvent = 'onload';
xDomain = true;
}
// HTTP basic authentication
@@ -36,13 +40,20 @@ module.exports = function xhrAdapter(resolve, reject, config) {
request.timeout = config.timeout;
// Listen for ready state
request.onload = function handleLoad() {
if (!request) {
request[loadEvent] = function handleLoad() {
if (!request || (request.readyState !== 4 && !xDomain)) {
return;
}
// The request errored out and we didn't get a response, this will be
// handled by onerror instead
if (request.status === 0) {
return;
}
// Prepare the response
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
var responseData = ['text', ''].indexOf(config.responseType || '') !== -1 ? request.responseText : request.response;
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
var response = {
data: transformData(
responseData,