【发布时间】:2011-12-22 16:40:54
【问题描述】:
我正在为自己开发一个 Twitter 网络应用程序。我正在检索最新的热门话题。
这是我的做法:
$.ajax({
url: 'http://api.twitter.com/1/trends/1.json',
dataType: 'jsonp',
success: function(data){
$.each(data[0].trends, function(i){
$('div#trending').hide().append("<p><a href='"+data[0].trends[i].url+"'>"+data[0].trends[i].name+"</a></p>").fadeIn(1000);
//Cache into LocalStorage
localStorage["trending"+i] = data[0].trends[i].name; //Name
localStorage["trendurl"+i] = data[0].trends[i].url;//URL
});
}
});
但有时我在开发它时,超出了速率限制。
如何检测是否超过了速率限制?
我似乎无法检测到是否显示此错误:
{"error":"Rate limit exceeded. Clients may not make more than 150 requests per hour.","request":"\/1\/trends\/1.json"}
我试过了:
success: function(data){
if(data[0].error != 'undefined'){
//load localstorage cache
}
}
但这似乎不起作用。 请帮忙。
谢谢:)
【问题讨论】:
标签: javascript jquery twitter jsonp