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) {
542542
543543QUnit . test ( "It doesn't stringify FormData" , function ( assert ) {
544544 var done = assert . async ( ) ;
545- var headers = { } ;
545+
546546 var formData = new FormData ( ) ;
547547 formData . append ( 'foo' , 'bar' ) ;
548548
@@ -575,8 +575,12 @@ QUnit.test("It doesn't stringify FormData", function(assert) {
575575 url : url ,
576576 data : formData
577577 } ) . then ( function ( value ) {
578- assert . equal ( value [ "Content-Type" ] , "application/json" ) ;
579578 assert . equal ( value . url , url ) ;
579+ assert . equal (
580+ typeof value [ "Content-Type" ] ,
581+ "undefined" ,
582+ "Content-Type should not be set"
583+ ) ;
580584 } , function ( reason ) {
581585 assert . notOk ( reason , "request failed with reason = " , reason ) ;
582586 } )
Original file line number Diff line number Diff line change @@ -232,17 +232,19 @@ function ajax(o) {
232232
233233 if ( isPost ) {
234234 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
236237 data = o . data ;
237238 } 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+ }
241247 }
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 ) ;
246248 } else {
247249 xhr . setRequestHeader ( "Content-Type" , o . contentType ) ;
248250 }
You can’t perform that action at this time.
0 commit comments