File tree Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Expand file tree Collapse file tree 2 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -542,7 +542,7 @@ if (hasLocalServer) {
542
542
543
543
QUnit . test ( "It doesn't stringify FormData" , function ( assert ) {
544
544
var done = assert . async ( ) ;
545
- var headers = { } ;
545
+
546
546
var formData = new FormData ( ) ;
547
547
formData . append ( 'foo' , 'bar' ) ;
548
548
@@ -575,8 +575,12 @@ QUnit.test("It doesn't stringify FormData", function(assert) {
575
575
url : url ,
576
576
data : formData
577
577
} ) . then ( function ( value ) {
578
- assert . equal ( value [ "Content-Type" ] , "application/json" ) ;
579
578
assert . equal ( value . url , url ) ;
579
+ assert . equal (
580
+ typeof value [ "Content-Type" ] ,
581
+ "undefined" ,
582
+ "Content-Type should not be set"
583
+ ) ;
580
584
} , function ( reason ) {
581
585
assert . notOk ( reason , "request failed with reason = " , reason ) ;
582
586
} )
Original file line number Diff line number Diff line change @@ -232,17 +232,19 @@ function ajax(o) {
232
232
233
233
if ( isPost ) {
234
234
if ( isFormData ) {
235
- // don't stringify FormData XHR handles it natively
235
+ // do not set "Content-Type" let the browser handle it
236
+ // do not stringify FormData XHR handles it natively
236
237
data = o . data ;
237
238
} else {
238
- data = ( isJsonContentType && ! isSimpleCors ) ?
239
- ( typeof o . data === "object" ? JSON . stringify ( o . data ) : o . data ) :
240
- param ( o . data ) ;
239
+ if ( isJsonContentType && ! isSimpleCors ) {
240
+ data = typeof o . data === "object" ? JSON . stringify ( o . data ) : o . data ;
241
+ xhr . setRequestHeader ( "Content-Type" , "application/json" ) ;
242
+ } else {
243
+ data = param ( o . data ) ;
244
+ // CORS simple: `Content-Type` has to be `application/x-www-form-urlencoded`:
245
+ xhr . setRequestHeader ( "Content-Type" , "application/x-www-form-urlencoded" ) ;
246
+ }
241
247
}
242
- // CORS simple: `Content-Type` has to be `application/x-www-form-urlencoded`:
243
- var setContentType = ( isJsonContentType && ! isSimpleCors ) ?
244
- "application/json" : "application/x-www-form-urlencoded" ;
245
- xhr . setRequestHeader ( "Content-Type" , setContentType ) ;
246
248
} else {
247
249
xhr . setRequestHeader ( "Content-Type" , o . contentType ) ;
248
250
}
You can’t perform that action at this time.
0 commit comments