// Build temporary JSONP function
if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
- jsonp = "jsonp" + jsc++;
+ jsonp = s.jsonpCallback || ("jsonp" + jsc++);
// Replace the =? sequence both in the query string and the data
if ( s.data ) {
s.dataType = "script";
// Handle JSONP-style loading
- window[ jsonp ] = function(tmp){
+ window[ jsonp ] = window[ jsonp ] || function(tmp){
data = tmp;
success();
complete();
});
test("jQuery.ajax() - JSONP, Local", function() {
- expect(7);
+ expect(8);
var count = 0;
- function plus(){ if ( ++count == 7 ) start(); }
+ function plus(){ if ( ++count == 8 ) start(); }
stop();
});
jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ jsonpCallback: "jsonpResults",
+ success: function(data){
+ ok( data.data, "JSON results returned (GET, custom callback name)" );
+ plus();
+ },
+ error: function(data){
+ ok( false, "Ajax error JSON (GET, custom callback name)" );
+ plus();
+ }
+ });
+
+ jQuery.ajax({
type: "POST",
url: "data/jsonp.php",
dataType: "jsonp",
});
});
+test("JSONP - Custom JSONP Callback", function() {
+ expect(1);
+ stop();
+
+ window.jsonpResults = function(data) {
+ ok( data.data, "JSON results returned (GET, custom callback function)" );
+ start();
+ };
+
+ jQuery.ajax({
+ url: "data/jsonp.php",
+ dataType: "jsonp",
+ jsonpCallback: "jsonpResults"
+ });
+});
+
test("jQuery.ajax() - JSONP, Remote", function() {
expect(4);