mirror of
https://github.com/jquery/jquery.git
synced 2026-04-20 03:01:22 -04:00
Replaces "text in-between" technique with a full-fledged one-level transitive search for converters (unit tests added). Also cleans up auto dataType determination and adds converter checks in order to guess the best dataType possible.
This commit is contained in:
@@ -2006,6 +2006,49 @@ test( "jQuery.ajax - statusCode" , function() {
|
||||
});
|
||||
});
|
||||
|
||||
test("jQuery.ajax - transitive conversions", function() {
|
||||
|
||||
expect( 8 );
|
||||
|
||||
stop();
|
||||
|
||||
jQuery.when(
|
||||
|
||||
jQuery.ajax( url("data/json.php") , {
|
||||
converters: {
|
||||
"json myjson": function( data ) {
|
||||
ok( true , "converter called" );
|
||||
return data;
|
||||
}
|
||||
},
|
||||
dataType: "myjson",
|
||||
success: function() {
|
||||
ok( true , "Transitive conversion worked" );
|
||||
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text" );
|
||||
strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType" );
|
||||
}
|
||||
}),
|
||||
|
||||
jQuery.ajax( url("data/json.php") , {
|
||||
converters: {
|
||||
"json myjson": function( data ) {
|
||||
ok( true , "converter called (*)" );
|
||||
return data;
|
||||
}
|
||||
},
|
||||
contents: false, /* headers are wrong so we ignore them */
|
||||
dataType: "* myjson",
|
||||
success: function() {
|
||||
ok( true , "Transitive conversion worked (*)" );
|
||||
strictEqual( this.dataTypes[0] , "text" , "response was retrieved as text (*)" );
|
||||
strictEqual( this.dataTypes[1] , "myjson" , "request expected myjson dataType (*)" );
|
||||
}
|
||||
})
|
||||
|
||||
).then( start , start );
|
||||
|
||||
});
|
||||
|
||||
test("jQuery.ajax - active counter", function() {
|
||||
ok( jQuery.active == 0, "ajax active counter should be zero: " + jQuery.active );
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user