(function( jQuery ) {
var jsc = jQuery.now(),
- jsre = /\=(?:\?|%3F)(&|$)/i,
+ jsre = /(\=)(?:\?|%3F)(&|$)|()(?:\?\?|%3F%3F)()/i,
rquery_jsonp = /\?/;
// Default jsonp settings
var jsonpCallback = s.jsonpCallback =
jQuery.isFunction( s.jsonpCallback ) ? s.jsonpCallback() : s.jsonpCallback,
- url = s.url.replace(jsre, "=" + jsonpCallback + "$1"),
- data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "=" + jsonpCallback + "$1") : s.data;
+ url = s.url.replace(jsre, "$1" + jsonpCallback + "$2"),
+ data = s.url === url && typeof(s.data) === "string" ? s.data.replace(jsre, "$1" + jsonpCallback + "$2") : s.data;
if ( url === s.url && data === s.data ) {
url += (rquery_jsonp.test( url ) ? "&" : "?") + s.jsonp + "=" + jsonpCallback;
<?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 } ])';
});
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();
}
});
+ 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",