}
equal( i, 1, "Test to make sure only one 'no-cache' parameter is there" );
ok( oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced" );
- if ( ++count == 6 ) {
+ if ( ++count === 6 ) {
start();
}
});
});
});
+
jQuery.each( [ "Same Domain", "Cross Domain" ], function( crossDomain, label ) {
- test( "jQuery.ajax() - JSONP, " + label, function() {
- expect( 24 );
+
+ asyncTest( "jQuery.ajax() - JSONP, Query String (?n)" + label, function() {
+ expect( 4 );
var count = 0;
function plus() {
- if ( ++count == 20 ) {
+ if ( ++count === 4 ) {
start();
}
}
- stop();
-
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- success: function( data ) {
- ok( data.data, "JSON results returned (GET, no callback)" );
- plus();
- },
- error: function( data ) {
- ok( false, "Ajax error JSON (GET, no callback)" );
- plus();
- }
- });
-
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- success: function( data ) {
- ok( data.data, ( this.alreadyDone ? "this re-used" : "first request" ) + ": JSON results returned (GET, no callback)" );
- if ( !this.alreadyDone ) {
- this.alreadyDone = true;
- jQuery.ajax( this );
- } else {
- plus();
- }
- },
- error: function( data ) {
- ok( false, "Ajax error JSON (GET, no callback)" );
- plus();
- }
- });
-
jQuery.ajax({
url: "data/jsonp.php?callback=?",
dataType: "jsonp",
}
});
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- data: "callback=?",
- success: function( data ) {
- ok( data.data, "JSON results returned (GET, data callback)" );
- plus();
- },
- error: function( data ) {
- ok( false, "Ajax error JSON (GET, data callback)" );
- plus();
- }
- });
-
jQuery.ajax({
url: "data/jsonp.php?callback=??",
dataType: "jsonp",
}
});
- jQuery.ajax({
- url: "data/jsonp.php",
- dataType: "jsonp",
- crossDomain: crossDomain,
- data: "callback=??",
- success: function( data ) {
- ok( data.data, "JSON results returned (GET, data context-free callback)" );
- plus();
- },
- error: function( data ) {
- ok( false, "Ajax error JSON (GET, data context-free callback)" );
- plus();
- }
- });
-
jQuery.ajax({
url: "data/jsonp.php/??",
dataType: "jsonp",
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - JSONP, Explicit jsonp/Callback param " + label, function() {
+ expect( 9 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 4 ) {
+ start();
+ }
+ }
jQuery.ajax({
url: "data/jsonp.php",
}
});
+ jQuery.ajax({
+ url: "data/jsonp.php?callback=XXX",
+ dataType: "jsonp",
+ jsonp: false,
+ jsonpCallback: "XXX",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
+ plus();
+ },
+ success: function( data ) {
+ ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
+ plus();
+ }
+ });
+ });
+
+
+ asyncTest( "jQuery.ajax() - JSONP, Callback in data, " + label, function() {
+ expect( 2 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 2 ) {
+ start();
+ }
+ }
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ data: "callback=?",
+ success: function( data ) {
+ ok( data.data, "JSON results returned (GET, data callback)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, data callback)" );
+ plus();
+ }
+ });
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ data: "callback=??",
+ success: function( data ) {
+ ok( data.data, "JSON results returned (GET, data context-free callback)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, data context-free callback)" );
+ plus();
+ }
+ });
+ });
+
+
+ asyncTest( "jQuery.ajax() - JSONP, POST, " + label, function() {
+ expect( 3 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 3 ) {
+ start();
+ }
+ }
+
jQuery.ajax({
type: "POST",
url: "data/jsonp.php",
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - JSONP, " + label, function() {
+ expect( 3 );
+
+ var count = 0;
+ function plus() {
+ if ( ++count === 2 ) {
+ start();
+ }
+ }
- //#7578
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
crossDomain: crossDomain,
- beforeSend: function() {
- strictEqual( this.cache, false, "cache must be false on JSON request" );
+ success: function( data ) {
+ ok( data.data, "JSON results returned (GET, no callback)" );
+ plus();
+ },
+ error: function( data ) {
+ ok( false, "Ajax error JSON (GET, no callback)" );
plus();
- return false;
}
});
jQuery.ajax({
- url: "data/jsonp.php?callback=XXX",
+ url: "data/jsonp.php",
dataType: "jsonp",
- jsonp: false,
- jsonpCallback: "XXX",
crossDomain: crossDomain,
- beforeSend: function() {
- ok( /^data\/jsonp.php\?callback=XXX&_=\d+$/.test( this.url ), "The URL wasn't messed with (GET, custom callback name with no url manipulation)" );
- plus();
- },
success: function( data ) {
- ok( data["data"], "JSON results returned (GET, custom callback name with no url manipulation)" );
- plus();
+ ok( data.data, ( this.alreadyDone ? "this re-used" : "first request" ) + ": JSON results returned (GET, no callback)" );
+ if ( !this.alreadyDone ) {
+ this.alreadyDone = true;
+
+ // NOTE: "this" will create another request identical
+ // to the CALLING request
+ jQuery.ajax( this );
+ } else {
+ plus();
+ }
},
error: function( data ) {
- ok( false, "Ajax error JSON (GET, custom callback name with no url manipulation)" );
+ ok( false, "Ajax error JSON (GET, no callback)" );
plus();
}
});
+ });
+
+ asyncTest( "jQuery.ajax() - #7578, " + label, function() {
+ expect( 1 );
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ crossDomain: crossDomain,
+ beforeSend: function() {
+ strictEqual( this.cache, false, "cache must be false on JSON request" );
+ start();
+ return false;
+ }
+ });
+ });
+
+ asyncTest( "jQuery.ajax() - #8205, " + label, function() {
+ expect( 2 );
- //#8205
jQuery.ajax({
url: "data/jsonp.php",
dataType: "jsonp",
return false;
}
});
- }).always( plus );
-
+ }).always(function() {
+ start();
+ });
});
});