git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
aea5b09
)
Added in support for $.ajax jsonpCallback (allowing you to specify the name of the...
author
John Resig
<jeresig@gmail.com>
Mon, 7 Dec 2009 01:17:14 +0000
(17:17 -0800)
committer
John Resig
<jeresig@gmail.com>
Mon, 7 Dec 2009 01:17:14 +0000
(17:17 -0800)
src/ajax.js
patch
|
blob
|
history
test/unit/ajax.js
patch
|
blob
|
history
diff --git
a/src/ajax.js
b/src/ajax.js
index
568a75d
..
7c5c838
100644
(file)
--- a/
src/ajax.js
+++ b/
src/ajax.js
@@
-221,7
+221,7
@@
jQuery.extend({
// Build temporary JSONP function
if ( s.dataType === "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) {
// 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 ) {
// Replace the =? sequence both in the query string and the data
if ( s.data ) {
@@
-235,7
+235,7
@@
jQuery.extend({
s.dataType = "script";
// Handle JSONP-style loading
s.dataType = "script";
// Handle JSONP-style loading
- window[ jsonp ] = function(tmp){
+ window[ jsonp ] = window[ jsonp ] || function(tmp){
data = tmp;
success();
complete();
data = tmp;
success();
complete();
diff --git
a/test/unit/ajax.js
b/test/unit/ajax.js
index
d827a15
..
4d63ce5
100644
(file)
--- a/
test/unit/ajax.js
+++ b/
test/unit/ajax.js
@@
-518,10
+518,10
@@
test("jQuery.getScript(String, Function) - no callback", function() {
});
test("jQuery.ajax() - JSONP, Local", function() {
});
test("jQuery.ajax() - JSONP, Local", function() {
- expect(7);
+ expect(8);
var count = 0;
var count = 0;
- function plus(){ if ( ++count == 7 ) start(); }
+ function plus(){ if ( ++count == 8 ) start(); }
stop();
stop();
@@
-580,6
+580,20
@@
test("jQuery.ajax() - JSONP, Local", function() {
});
jQuery.ajax({
});
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",
type: "POST",
url: "data/jsonp.php",
dataType: "jsonp",
@@
-624,6
+638,22
@@
test("jQuery.ajax() - JSONP, Local", function() {
});
});
});
});
+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);
test("jQuery.ajax() - JSONP, Remote", function() {
expect(4);