Created
February 12, 2012 21:05
-
-
Save tvandervossen/1810845 to your computer and use it in GitHub Desktop.
Quick patch for JSONP error callback support in Zepto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ajax.js b/src/ajax.js | |
index d75e13c..f9d399f 100644 | |
--- a/src/ajax.js | |
+++ b/src/ajax.js | |
@@ -99,6 +99,11 @@ | |
}, | |
xhr = { abort: abort }, abortTimeout; | |
+ if (options.error) script.onerror = function() { | |
+ xhr.abort(); | |
+ options.error(); | |
+ }; | |
+ | |
window[callbackName] = function(data){ | |
clearTimeout(abortTimeout); | |
$(script).remove(); | |
diff --git a/test/ajax.html b/test/ajax.html | |
index fc0dd8d..5d6e3b5 100644 | |
--- a/test/ajax.html | |
+++ b/test/ajax.html | |
@@ -118,6 +118,16 @@ | |
t.assertEqual(1, $('script[src^=fixtures]').size()); | |
t.assertIn('abort', xhr); | |
}, | |
+ | |
+ testAjaxGetJSONPErrorCallback: function(t){ | |
+ var successFired, errorFired, xhr = $.ajax({ | |
+ type: 'GET', | |
+ url: 'fixtures/404.js?callback=?×tamp='+(+new Date), | |
+ dataType: 'jsonp', | |
+ success: function() { t.refute(true); }, | |
+ error: function() { t.assert(true); } | |
+ }); | |
+ }, | |
testAjaxLoad: function(t) { | |
var testEl = $('#ajax_load'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment