How do I handle twitter fail whale in JSONP

。_饼干妹妹 提交于 2019-12-11 03:19:24

问题


I load

http://search.twitter.com/search.json?callback=formatTweets&q=somehashTag&timestamp="+new Date().getTime();

I suddenly got

Error: illegal character
Source File: http://search.twitter.com/search.json?callback=formatTweets&q=sunshine&timestamp=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+"&timestamp="+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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!