问题
I load
http://search.twitter.com/search.json?callback=formatTweets&q=somehashTag×tamp="+new Date().getTime();
I suddenly got
Error: illegal character
Source File: http://search.twitter.com/search.json?callback=formatTweets&q=sunshine×tamp=1305631097599
Line: 1, Column: 13
Source Code:
formatTweets(�
because twitter sent me a fail whale.
Can you think of a way to detect and handle this?
Here is my invocation:
function loadTweets() {
var head = document.getElementsByTagName('head');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "http://search.twitter.com/search.json?callback=formatTweets&q="+hashTag+"×tamp="+new Date().getTime();
head[0].appendChild(script);
}
回答1:
I found this question which had some interesting answers. To summarize, one approach is to wrap all errors returned by the server in JSON, and another provides a link to a nice looking reinterpretation of jQuery's JSONP implementation.
来源:https://stackoverflow.com/questions/6030022/how-do-i-handle-twitter-fail-whale-in-jsonp