File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -579,11 +579,6 @@ jQuery.extend({
579
579
}
580
580
}
581
581
582
- // Set the correct header, if data is being sent
583
- if ( s . data && s . hasContent && s . contentType !== false || options . contentType ) {
584
- jqXHR . setRequestHeader ( "Content-Type" , s . contentType ) ;
585
- }
586
-
587
582
// Set the Accepts header for the server, depending on the dataType
588
583
jqXHR . setRequestHeader (
589
584
"Accept" ,
@@ -606,6 +601,11 @@ jQuery.extend({
606
601
return jqXHR . abort ( ) ;
607
602
}
608
603
604
+ // Set the correct header, if data is being sent
605
+ if ( s . data && s . hasContent && s . contentType !== false || options . contentType ) {
606
+ jqXHR . setRequestHeader ( "Content-Type" , s . contentType ) ;
607
+ }
608
+
609
609
// Aborting is no longer a cancellation
610
610
strAbort = "abort" ;
611
611
Original file line number Diff line number Diff line change @@ -2022,6 +2022,37 @@ module( "ajax", {
2022
2022
} ) ;
2023
2023
} ) ;
2024
2024
2025
+ asyncTest ( "Send correct \"Content-type\" if data is set in \"beforeSend\" method gh#1801" , 2 ,
2026
+ function ( ) {
2027
+ var oldSetRequestHeader ;
2028
+
2029
+ jQuery . ajax ( {
2030
+ url : "/" ,
2031
+ method : "post" ,
2032
+ beforeSend : function ( xhr , settings ) {
2033
+ oldSetRequestHeader = xhr . setRequestHeader ;
2034
+ settings . data = "test" ;
2035
+
2036
+ xhr . setRequestHeader = function ( name , value ) {
2037
+ strictEqual ( name , "Content-Type" , "correct header" ) ;
2038
+ strictEqual ( value ,
2039
+ "application/x-www-form-urlencoded; charset=UTF-8" ,
2040
+ "correct value"
2041
+ ) ;
2042
+ } ;
2043
+ }
2044
+ } ) . done ( function ( data , textStatus , jqXHR ) {
2045
+ jqXHR . old = oldSetRequestHeader ;
2046
+
2047
+ start ( ) ;
2048
+
2049
+ } ) . fail ( function ( jqXHR ) {
2050
+ jqXHR . old = oldSetRequestHeader ;
2051
+
2052
+ start ( ) ;
2053
+ } ) ;
2054
+ } ) ;
2055
+
2025
2056
//----------- jQuery.active
2026
2057
2027
2058
test ( "jQuery.active" , 1 , function ( ) {
You can’t perform that action at this time.
0 commit comments