如何在JSONP中处理Twitter失败的鲸鱼 [英] How do I handle twitter fail whale in JSONP

查看:62
本文介绍了如何在JSONP中处理Twitter失败的鲸鱼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载

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

我突然得到

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?

这是我的调用:

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);
}

推荐答案

我发现了这个问题,其中有一些有趣的答案.总而言之,一种方法是将服务器返回的所有错误包装在JSON中,另一种方法提供一个链接到jQuery JSONP实现的漂亮外观.

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.

这篇关于如何在JSONP中处理Twitter失败的鲸鱼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆