3
3
const jQueryDeferred = require ( 'jquery-deferred' ) ;
4
4
const jQueryParam = require ( 'jquery-param' ) ;
5
5
6
- const jqueryFunction = function ( subject ) {
6
+ const jqueryFunction = function ( subject ) {
7
7
let events = subject . events || { } ;
8
8
9
9
if ( subject && subject === subject . window )
@@ -51,13 +51,15 @@ const jqueryFunction = function(subject) {
51
51
} ;
52
52
} ;
53
53
54
- const xhr = function ( ) {
54
+ const xhr = function ( ) {
55
55
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 ) { }
58
60
} ;
59
61
60
- const ajax = function ( options ) {
62
+ const ajax = function ( options ) {
61
63
const request = xhr ( ) ;
62
64
63
65
if ( options . xhrFields && options . xhrFields . withCredentials ) {
@@ -83,8 +85,8 @@ const ajax = function(options) {
83
85
request . withCredentials = options . xhrFields . withCredentials ;
84
86
var cacheBuster = "_=" + new Date ( ) . getTime ( ) ;
85
87
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 ) {
88
90
options . url += "&" + cacheBuster ;
89
91
} else {
90
92
options . url = options . url . replace ( / _ = \d + / , cacheBuster ) ;
@@ -101,7 +103,7 @@ const ajax = function(options) {
101
103
request . send ( options . data . data && `data=${ encodeURIComponent ( options . data . data ) } ` ) ;
102
104
103
105
return {
104
- abort : function ( reason ) {
106
+ abort : function ( reason ) {
105
107
return request . abort ( reason ) ;
106
108
}
107
109
} ;
@@ -113,13 +115,13 @@ module.exports = jQueryDeferred.extend(
113
115
{
114
116
defaultAjaxHeaders : null ,
115
117
ajax : ajax ,
116
- inArray : ( arr , item ) => arr . indexOf ( item ) !== - 1 ,
118
+ inArray : ( arr , item ) => arr . indexOf ( item ) !== - 1 ,
117
119
trim : str => str && str . trim ( ) ,
118
120
isEmptyObject : obj => ! obj || Object . keys ( obj ) . length === 0 ,
119
- makeArray : arr => [ ] . slice . call ( arr , 0 ) ,
121
+ makeArray : arr => [ ] . slice . call ( arr , 0 ) ,
120
122
param : obj => jQueryParam ( obj ) ,
121
123
support : {
122
- cors : ( function ( ) {
124
+ cors : ( function ( ) {
123
125
const xhrObj = xhr ( ) ;
124
126
return ! ! xhrObj && ( "withCredentials" in xhrObj ) ;
125
127
} ) ( )
0 commit comments