"*": "*/*"
},
- autoDataType: {
+ contents: {
xml: /xml/,
html: /html/,
json: /json/
// List of data converters
// 1) key format is "source_type destination_type" (a single space in-between)
// 2) the catchall symbol "*" can be used for source_type
- dataConverters: {
+ converters: {
// Convert anything to text
"* text": window.String,
oneConv,
convertion,
dataTypes = s.dataTypes,
- dataConverters = s.dataConverters,
+ converters = s.converters,
responses = {
"xml": "XML",
"text": "Text"
if ( prev !== "*" && current !== "*" && prev !== current ) {
oneConv = conv1 =
- dataConverters[ ( conversion = prev + " " + current ) ] ||
- dataConverters[ "* " + current ];
+ converters[ ( conversion = prev + " " + current ) ] ||
+ converters[ "* " + current ];
if ( oneConv !== true ) {
if ( ! oneConv && prev !== "text" && current !== "text" ) {
- conv1 = dataConverters[ prev + " text" ] || dataConverters[ "* text" ];
- conv2 = dataConverters[ "text " + current ];
+ conv1 = converters[ prev + " text" ] || converters[ "* text" ];
+ conv2 = converters[ "text " + current ];
}
if ( oneConv || conv1 && conv2 ) {
// (for those transports that can give text or xml responses)
function determineDataType( s , ct , text , xml ) {
- var autoDataType = s.autoDataType,
+ var contents = s.contents,
type,
regexp,
dataTypes = s.dataTypes,
// Auto (xml, json, script or text determined given headers)
if ( transportDataType === "*" ) {
- for ( type in autoDataType ) {
- if ( ( regexp = autoDataType[ type ] ) && regexp.test( ct ) ) {
+ for ( type in contents ) {
+ if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
transportDataType = dataTypes[0] = type;
break;
}
response = text;
- // If it's not really text, defer to dataConverters
+ // If it's not really text, defer to converters
if ( transportDataType !== "text" ) {
dataTypes.unshift( "text" );
}
}, 13);
});
-test("jQuery.ajax() - success/error callbacks (remote)", function() {
-
- var supports = jQuery.support.cors;
-
- expect( supports ? 9 : 4 );
-
- jQuery.ajaxSetup({ timeout: 0 });
-
- stop();
-
- setTimeout(function(){
- jQuery('#foo').ajaxStart(function(){
- ok( true, "ajaxStart" );
- }).ajaxStop(function(){
- ok( true, "ajaxStop" );
- start();
- }).ajaxSend(function(){
- ok( supports , "ajaxSend" );
- }).ajaxComplete(function(){
- ok( true, "ajaxComplete" );
- }).ajaxError(function(){
- ok( ! supports, "ajaxError" );
- }).ajaxSuccess(function(){
- ok( supports, "ajaxSuccess" );
- });
-
- jQuery.ajax({
- // JULIAN TODO: Get an url especially for jQuery
- url: "http://rockstarapps.com/test.php",
- dataType: "text",
- beforeSend: function(){ ok(supports, "beforeSend"); },
- success: function( val ){ ok(supports, "success"); ok(supports && val.length, "data received"); },
- error: function(_ , a , b ){ ok(false, "error"); },
- complete: function(){ ok(supports, "complete"); }
- });
- }, 13);
-});
-
test("jQuery.ajax() - success callbacks (late binding)", function() {
expect( 8 );
jQuery.ajax({
url: url("data/json.php"),
data: { header: "json", json: "array" },
- autoDataType: {
+ contents: {
json: false
},
success: function( text ) {
equals( typeof text , "string" , "json wasn't auto-determined" );
- var json = this.dataConverters["text json"]( text );
+ var json = jQuery.parseJSON( text );
ok( json.length >= 2, "Check length");
equals( json[0].name, 'John', 'Check JSON: first, name' );
equals( json[0].age, 21, 'Check JSON: first, age' );
stop();
var i = 2;
-
- jQuery.ajax({
- url: 'http://somewebsitethatdoesnotexist.com',
+
+ if ( jQuery.ajax({
+ url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); }
- });
-
- jQuery.ajax({
+ }) === false ) {
+ ok( true , "no transport" );
+ if ( ! --i ) start();
+ }
+
+ if ( jQuery.ajax({
url: 'http://www.google.com',
success: function(){ ok( false , "success" ); },
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
complete: function() { if ( ! --i ) start(); }
- });
-
+ }) === false ) {
+ ok( true , "no transport" );
+ if ( ! --i ) start();
+ }
+
});
test("jQuery ajax - atom+xml", function() {