-
6 Mar 2012 7:37 PM #1
JSONP requests failing after first call
JSONP requests failing after first call
Version tested: Sencha Touch 1.1.1
Subsequent JSONP requests do not execute after a request which does not return successfully. Additionally, there seems to be an issue with subsequent calls even when the return is a success. Setting "Ext.util.JSONP.current = undefined" works around the latter issue and allows more calls to be made. This does not work when the call fails, however.
The following code demonstrates the problem. The 'valid' services called are public Flickr services, and the the invalid call is to localhost:82 which is assumed to be closed.
Code to reproduce:
Code:<!DOCTYPE html> <html> <head> <script src="src/sencha-touch-debug-w-comments.js"></script> <script> // Flickr callback function jsonFlickrFeed(data) { console.log("callback invoked"); console.dir(data); // Without this statement, NO subsequent JSONP requests execute, regardless of success/failure. Ext.util.JSONP.current = undefined; } Ext.onReady(function () { // This will succeed. console.log("calling valid service"); Ext.util.JSONP.request({ url:'http://www.flickr.com/services/feeds/photos_public.gne?format=json' }); // This will fail setTimeout(function () { console.log("calling invalid jsonp service"); try { Ext.util.JSONP.request({ url:'http://127.0.0.1:82' }); } catch (e) { console.log(e); } }, 1000); // This will never execute. setTimeout(function () { console.log("retrying valid service"); try { Ext.util.JSONP.request({ url:'http://api.flickr.com/services/feeds/forums.gne?format=json' }); } catch (e) { console.log(e); } }, 4000); }); </script> </head> <body> </body> </html>Last edited by jdspdx; 6 Mar 2012 at 7:44 PM. Reason: code displaying improperly
-
6 Mar 2012 11:11 PM #2
This appears to be because Ext.util.JSONP does not support static callback names properly.
Does this snippet of code in Ext.util.JSONP.request make sense?
This results in a URL parameter of the form "MyCode.callback=Ext.util.JSONP.callback".Code:if (o.callbackKey) { o.params[o.callbackKey] = 'Ext.util.JSONP.callback'; }
The state (Ext.util.JSONP.current) is never getting properly reset, because Ext.util.JSONP.callback never executes.
-
8 Mar 2012 8:15 PM #3
There's also insufficient error handling for when JSONP requests fail. No exceptions are thrown that are catchable. How is one supposed to determine whether or not a request failed?
Thank you for reporting this bug. We will make it our priority to review this report.


Reply With Quote