diff options
author | jaubourg <j@ubourg.net> | 2011-01-12 18:36:00 +0100 |
---|---|---|
committer | jaubourg <j@ubourg.net> | 2011-01-12 18:36:00 +0100 |
commit | 0c51e9d55f39366cab14719b80cb7e989c716351 (patch) | |
tree | e602d1bcd82989b883443994eaa1970b9e86773c /test | |
parent | f83cdc3c4c134b2796335e9f9806f3b67e7ca87f (diff) | |
download | jquery-0c51e9d55f39366cab14719b80cb7e989c716351.tar.gz jquery-0c51e9d55f39366cab14719b80cb7e989c716351.zip |
Fixes #4897. Added ?? as a context-insensitive placeholder for the callback name of a JSONP request. Unit tests provided.
Diffstat (limited to 'test')
-rw-r--r-- | test/data/jsonp.php | 4 | ||||
-rw-r--r-- | test/unit/ajax.js | 57 |
2 files changed, 59 insertions, 2 deletions
diff --git a/test/data/jsonp.php b/test/data/jsonp.php index 9ae1d8487..6c13d72e9 100644 --- a/test/data/jsonp.php +++ b/test/data/jsonp.php @@ -1,6 +1,10 @@ <?php error_reporting(0); $callback = $_REQUEST['callback']; +if ( ! $callback ) { + $callback = explode("?",end(explode("/",$_SERVER['REQUEST_URI']))); + $callback = $callback[0]; +} $json = $_REQUEST['json']; if($json) { echo $callback . '([ {"name": "John", "age": 21}, {"name": "Peter", "age": 25 } ])'; diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 4162d585a..10c2e7183 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1115,10 +1115,10 @@ test("jQuery.getScript(String, Function) - no callback", function() { }); test("jQuery.ajax() - JSONP, Local", function() { - expect(10); + expect(14); var count = 0; - function plus(){ if ( ++count == 10 ) start(); } + function plus(){ if ( ++count == 14 ) start(); } stop(); @@ -1163,6 +1163,59 @@ test("jQuery.ajax() - JSONP, Local", function() { }); jQuery.ajax({ + url: "data/jsonp.php?callback=??", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, url context-free callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url context-free callback)" ); + plus(); + } + }); + + jQuery.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + 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", + success: function(data){ + ok( data.data, "JSON results returned (GET, REST-like)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, REST-like)" ); + plus(); + } + }); + + jQuery.ajax({ + url: "data/jsonp.php/???json=1", + dataType: "jsonp", + success: function(data){ + strictEqual( jQuery.type(data), "array", "JSON results returned (GET, REST-like with param)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, REST-like with param)" ); + plus(); + } + }); + + jQuery.ajax({ url: "data/jsonp.php", dataType: "jsonp", data: { |