Renamed several ajaxSettings options. Removed cors test, fixed failing cors test.
This commit is contained in:
parent
97b32d7830
commit
8c9d32723a
4 changed files with 27 additions and 59 deletions
22
src/ajax.js
22
src/ajax.js
|
@ -183,7 +183,7 @@ jQuery.extend({
|
||||||
"*": "*/*"
|
"*": "*/*"
|
||||||
},
|
},
|
||||||
|
|
||||||
autoDataType: {
|
contents: {
|
||||||
xml: /xml/,
|
xml: /xml/,
|
||||||
html: /html/,
|
html: /html/,
|
||||||
json: /json/
|
json: /json/
|
||||||
|
@ -208,7 +208,7 @@ jQuery.extend({
|
||||||
// List of data converters
|
// List of data converters
|
||||||
// 1) key format is "source_type destination_type" (a single space in-between)
|
// 1) key format is "source_type destination_type" (a single space in-between)
|
||||||
// 2) the catchall symbol "*" can be used for source_type
|
// 2) the catchall symbol "*" can be used for source_type
|
||||||
dataConverters: {
|
converters: {
|
||||||
|
|
||||||
// Convert anything to text
|
// Convert anything to text
|
||||||
"* text": window.String,
|
"* text": window.String,
|
||||||
|
@ -398,7 +398,7 @@ jQuery.extend({
|
||||||
oneConv,
|
oneConv,
|
||||||
convertion,
|
convertion,
|
||||||
dataTypes = s.dataTypes,
|
dataTypes = s.dataTypes,
|
||||||
dataConverters = s.dataConverters,
|
converters = s.converters,
|
||||||
responses = {
|
responses = {
|
||||||
"xml": "XML",
|
"xml": "XML",
|
||||||
"text": "Text"
|
"text": "Text"
|
||||||
|
@ -420,14 +420,14 @@ jQuery.extend({
|
||||||
if ( prev !== "*" && current !== "*" && prev !== current ) {
|
if ( prev !== "*" && current !== "*" && prev !== current ) {
|
||||||
|
|
||||||
oneConv = conv1 =
|
oneConv = conv1 =
|
||||||
dataConverters[ ( conversion = prev + " " + current ) ] ||
|
converters[ ( conversion = prev + " " + current ) ] ||
|
||||||
dataConverters[ "* " + current ];
|
converters[ "* " + current ];
|
||||||
|
|
||||||
if ( oneConv !== true ) {
|
if ( oneConv !== true ) {
|
||||||
|
|
||||||
if ( ! oneConv && prev !== "text" && current !== "text" ) {
|
if ( ! oneConv && prev !== "text" && current !== "text" ) {
|
||||||
conv1 = dataConverters[ prev + " text" ] || dataConverters[ "* text" ];
|
conv1 = converters[ prev + " text" ] || converters[ "* text" ];
|
||||||
conv2 = dataConverters[ "text " + current ];
|
conv2 = converters[ "text " + current ];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( oneConv || conv1 && conv2 ) {
|
if ( oneConv || conv1 && conv2 ) {
|
||||||
|
@ -841,7 +841,7 @@ jQuery.each( [ "prefilter" , "transport" ] , function( _ , name ) {
|
||||||
// (for those transports that can give text or xml responses)
|
// (for those transports that can give text or xml responses)
|
||||||
function determineDataType( s , ct , text , xml ) {
|
function determineDataType( s , ct , text , xml ) {
|
||||||
|
|
||||||
var autoDataType = s.autoDataType,
|
var contents = s.contents,
|
||||||
type,
|
type,
|
||||||
regexp,
|
regexp,
|
||||||
dataTypes = s.dataTypes,
|
dataTypes = s.dataTypes,
|
||||||
|
@ -851,8 +851,8 @@ function determineDataType( s , ct , text , xml ) {
|
||||||
// Auto (xml, json, script or text determined given headers)
|
// Auto (xml, json, script or text determined given headers)
|
||||||
if ( transportDataType === "*" ) {
|
if ( transportDataType === "*" ) {
|
||||||
|
|
||||||
for ( type in autoDataType ) {
|
for ( type in contents ) {
|
||||||
if ( ( regexp = autoDataType[ type ] ) && regexp.test( ct ) ) {
|
if ( ( regexp = contents[ type ] ) && regexp.test( ct ) ) {
|
||||||
transportDataType = dataTypes[0] = type;
|
transportDataType = dataTypes[0] = type;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -871,7 +871,7 @@ function determineDataType( s , ct , text , xml ) {
|
||||||
|
|
||||||
response = text;
|
response = text;
|
||||||
|
|
||||||
// If it's not really text, defer to dataConverters
|
// If it's not really text, defer to converters
|
||||||
if ( transportDataType !== "text" ) {
|
if ( transportDataType !== "text" ) {
|
||||||
dataTypes.unshift( "text" );
|
dataTypes.unshift( "text" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ jQuery.ajax.prefilter("json jsonp", function(s) {
|
||||||
}, s.complete ];
|
}, s.complete ];
|
||||||
|
|
||||||
// Use data converter to retrieve json after script execution
|
// Use data converter to retrieve json after script execution
|
||||||
s.dataConverters["script json"] = function() {
|
s.converters["script json"] = function() {
|
||||||
if ( ! responseContainer ) {
|
if ( ! responseContainer ) {
|
||||||
jQuery.error( jsonpCallback + " was not called" );
|
jQuery.error( jsonpCallback + " was not called" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ jQuery.extend( true, jQuery.ajaxSettings , {
|
||||||
script: "text/javascript, application/javascript"
|
script: "text/javascript, application/javascript"
|
||||||
},
|
},
|
||||||
|
|
||||||
autoDataType: {
|
contents: {
|
||||||
script: /javascript/
|
script: /javascript/
|
||||||
},
|
},
|
||||||
|
|
||||||
dataConverters: {
|
converters: {
|
||||||
"text script": jQuery.globalEval
|
"text script": jQuery.globalEval
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -70,44 +70,6 @@ test("jQuery.ajax() - success callbacks - (url, options) syntax", function() {
|
||||||
}, 13);
|
}, 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() {
|
test("jQuery.ajax() - success callbacks (late binding)", function() {
|
||||||
expect( 8 );
|
expect( 8 );
|
||||||
|
|
||||||
|
@ -1328,12 +1290,12 @@ test("jQuery.ajax() - json by content-type disabled with options", function() {
|
||||||
jQuery.ajax({
|
jQuery.ajax({
|
||||||
url: url("data/json.php"),
|
url: url("data/json.php"),
|
||||||
data: { header: "json", json: "array" },
|
data: { header: "json", json: "array" },
|
||||||
autoDataType: {
|
contents: {
|
||||||
json: false
|
json: false
|
||||||
},
|
},
|
||||||
success: function( text ) {
|
success: function( text ) {
|
||||||
equals( typeof text , "string" , "json wasn't auto-determined" );
|
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");
|
ok( json.length >= 2, "Check length");
|
||||||
equals( json[0].name, 'John', 'Check JSON: first, name' );
|
equals( json[0].name, 'John', 'Check JSON: first, name' );
|
||||||
equals( json[0].age, 21, 'Check JSON: first, age' );
|
equals( json[0].age, 21, 'Check JSON: first, age' );
|
||||||
|
@ -1677,19 +1639,25 @@ test("jQuery ajax - failing cross-domain", function() {
|
||||||
|
|
||||||
var i = 2;
|
var i = 2;
|
||||||
|
|
||||||
jQuery.ajax({
|
if ( jQuery.ajax({
|
||||||
url: 'http://somewebsitethatdoesnotexist.com',
|
url: 'http://somewebsitethatdoesnotexist-67864863574657654.com',
|
||||||
success: function(){ ok( false , "success" ); },
|
success: function(){ ok( false , "success" ); },
|
||||||
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
|
error: function(xhr,_,e){ ok( true , "file not found: " + xhr.status + " => " + e ); },
|
||||||
complete: function() { if ( ! --i ) start(); }
|
complete: function() { if ( ! --i ) start(); }
|
||||||
});
|
}) === false ) {
|
||||||
|
ok( true , "no transport" );
|
||||||
|
if ( ! --i ) start();
|
||||||
|
}
|
||||||
|
|
||||||
jQuery.ajax({
|
if ( jQuery.ajax({
|
||||||
url: 'http://www.google.com',
|
url: 'http://www.google.com',
|
||||||
success: function(){ ok( false , "success" ); },
|
success: function(){ ok( false , "success" ); },
|
||||||
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
|
error: function(xhr,_,e){ ok( true , "access denied: " + xhr.status + " => " + e ); },
|
||||||
complete: function() { if ( ! --i ) start(); }
|
complete: function() { if ( ! --i ) start(); }
|
||||||
});
|
}) === false ) {
|
||||||
|
ok( true , "no transport" );
|
||||||
|
if ( ! --i ) start();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue