@@ -44,7 +44,7 @@ utils.ajax = (function() {
44
44
( xhr . status === 0 && window . location . protocol === 'file:' )
45
45
} ;
46
46
47
- var end = function ( xhr , options , promise ) {
47
+ var end = function ( xhr , options , deferred ) {
48
48
return function ( ) {
49
49
if ( xhr . readyState !== 4 ) return ;
50
50
@@ -54,12 +54,11 @@ utils.ajax = (function() {
54
54
// Check for validity.
55
55
if ( isValid ( xhr ) ) {
56
56
if ( options . success ) options . success ( data ) ;
57
- if ( promise ) Backbone . resolveDeferred ( promise , true , [ data , xhr ] ) ;
57
+ if ( deferred ) deferred . resolve ( data ) ;
58
58
} else {
59
59
var error = new Error ( 'Server responded with a status of ' + status ) ;
60
- error . code = status ;
61
60
if ( options . error ) options . error ( xhr , status , error ) ;
62
- if ( promise ) Backbone . resolveDeferred ( promise , false , [ xhr ] ) ;
61
+ if ( deferred ) deferred . reject ( xhr ) ;
63
62
}
64
63
}
65
64
} ;
@@ -69,14 +68,16 @@ utils.ajax = (function() {
69
68
if ( options . method == null ) options . method = 'GET' ;
70
69
71
70
var xhr = new XMLHttpRequest ( ) ;
72
- var promise = Backbone . Deferred && Backbone . Deferred ( ) ;
71
+ var deferred = Backbone . Deferred && Backbone . Deferred ( ) ;
72
+
73
73
if ( options . credentials ) options . withCredentials = true ;
74
- xhr . addEventListener ( 'readystatechange' , end ( xhr , options , promise ) ) ;
74
+ xhr . addEventListener ( 'readystatechange' , end ( xhr , options , deferred ) ) ;
75
75
xhr . open ( options . method , options . url , true ) ;
76
76
if ( options . headers ) for ( var key in options . headers ) {
77
77
xhr . setRequestHeader ( key , options . headers [ key ] ) ;
78
78
}
79
79
xhr . send ( options . data ) ;
80
- return promise ;
80
+
81
+ return deferred ? deferred . promise : undefined ;
81
82
} ;
82
83
} ) ( ) ;
0 commit comments