Skip to content

Commit 1901048

Browse files
modify xhr object timeout to 2 mins
1 parent 8258c11 commit 1901048

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/jQueryShim.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const jQueryDeferred = require('jquery-deferred');
44
const jQueryParam = require('jquery-param');
55

6-
const jqueryFunction = function(subject) {
6+
const jqueryFunction = function (subject) {
77
let events = subject.events || {};
88

99
if (subject && subject === subject.window)
@@ -51,13 +51,15 @@ const jqueryFunction = function(subject) {
5151
};
5252
};
5353

54-
const xhr = function() {
54+
const xhr = function () {
5555
try {
56-
return new window.XMLHttpRequest();
57-
} catch (e) {}
56+
var xhrObj = new window.XMLHttpRequest()
57+
xhrObj.timeout = 120000;
58+
return xhrObj;
59+
} catch (e) { }
5860
};
5961

60-
const ajax = function(options) {
62+
const ajax = function (options) {
6163
const request = xhr();
6264

6365
if (options.xhrFields && options.xhrFields.withCredentials) {
@@ -83,8 +85,8 @@ const ajax = function(options) {
8385
request.withCredentials = options.xhrFields.withCredentials;
8486
var cacheBuster = "_=" + new Date().getTime();
8587
if (options.url.indexOf("?") === -1) {
86-
options.url += "?" + cacheBuster;
87-
} else if (options.url.indexOf("_=") === -1) {
88+
options.url += "?" + cacheBuster;
89+
} else if (options.url.indexOf("_=") === -1) {
8890
options.url += "&" + cacheBuster;
8991
} else {
9092
options.url = options.url.replace(/_=\d+/, cacheBuster);
@@ -101,7 +103,7 @@ const ajax = function(options) {
101103
request.send(options.data.data && `data=${encodeURIComponent(options.data.data)}`);
102104

103105
return {
104-
abort: function(reason) {
106+
abort: function (reason) {
105107
return request.abort(reason);
106108
}
107109
};
@@ -113,13 +115,13 @@ module.exports = jQueryDeferred.extend(
113115
{
114116
defaultAjaxHeaders: null,
115117
ajax: ajax,
116-
inArray: (arr,item) => arr.indexOf(item) !== -1,
118+
inArray: (arr, item) => arr.indexOf(item) !== -1,
117119
trim: str => str && str.trim(),
118120
isEmptyObject: obj => !obj || Object.keys(obj).length === 0,
119-
makeArray: arr => [].slice.call(arr,0),
121+
makeArray: arr => [].slice.call(arr, 0),
120122
param: obj => jQueryParam(obj),
121123
support: {
122-
cors: (function() {
124+
cors: (function () {
123125
const xhrObj = xhr();
124126
return !!xhrObj && ("withCredentials" in xhrObj);
125127
})()

0 commit comments

Comments
 (0)