File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,24 @@ if (hasLocalServer) {
50
50
done ( ) ;
51
51
} ) ;
52
52
} ) ;
53
+
54
+ QUnit . test ( "synchronous get request" , function ( assert ) {
55
+ var done = assert . async ( ) ;
56
+ var ok = true ;
57
+ ajax ( {
58
+ type : "get" ,
59
+ url : __dirname + "/can-ajax-test-result.json" ,
60
+ async : false ,
61
+ success : function ( ) {
62
+ assert . ok ( ok , "Callback happens before returning." ) ;
63
+ }
64
+ } ) . then ( function ( ) {
65
+ assert . ok ( ! ok , "Promise resolves after returning" ) ;
66
+ done ( ) ;
67
+ } ) ;
68
+
69
+ ok = false ;
70
+ } ) ;
53
71
}
54
72
55
73
QUnit . test ( "added to namespace (#99)" , function ( assert ) {
Original file line number Diff line number Diff line change @@ -140,6 +140,8 @@ function ajax(o) {
140
140
return canReflect . assignDeep ( a , b ) ;
141
141
} ) ;
142
142
143
+ var async = o . async !== false ;
144
+
143
145
// Set the default contentType
144
146
if ( ! o . contentType ) {
145
147
o . contentType = o . type . toUpperCase ( ) === "GET" ?
@@ -202,7 +204,7 @@ function ajax(o) {
202
204
if ( ! isPost && o . data ) {
203
205
url += "?" + ( isJsonContentType ? JSON . stringify ( o . data ) : param ( o . data ) ) ;
204
206
}
205
- xhr . open ( type , url ) ;
207
+ xhr . open ( type , url , async ) ;
206
208
207
209
// For CORS to send a "simple" request (to avoid a preflight check), the following methods are allowed: GET/POST/HEAD,
208
210
// see https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Simple_requests
You can’t perform that action at this time.
0 commit comments