我正在制作一个html页面,旨在在PC上本地运行,最好没有本地服务器运行(file://)。我也使用jQuery使操纵/ AJAX更容易一些。从本地主机或文件访问JSON服务://
我想从twitter API加载2个结果,但我得到一个错误。代码如下:
$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=someuser&count=9", {},
function (data) {
$.each(data.items, doSomething1);
});
$.getJSON("http://search.twitter.com/search.json?q=somequery&result_type=recent&count=9", {},
function (data) {
$.each(data.items, doSomething2);
});
我也尝试了下面的代码,但它没有改变结果。
$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json",
{
count: "9",
screen_name: "someuser"
},
function(data) {
$.each(data.items, updateAWTweets);
});
$.getJSON("http://search.twitter.com/search.json",
{
q: "somequery",
result_type: "recent",
count: "9"
},
function(data) {
$.each(data.items, updateHashTagTweets);
});
我得到了镀铬以下错误(本地主机服务器上):
XMLHttpRequest cannot load http://search.twitter.com/search.json?q=somequery&result_type=recent&count=9. Origin http://localhost:62153 is not allowed by Access-Control-Allow-Origin.
或(与文件://链接)
XMLHttpRequest cannot load http://api.twitter.com/1/statuses/user_timeline.json?screen_name=someuser&count=9. Origin null is not allowed by Access-Control-Allow-Origin.
有谁知道我可以修复这个?
该错误是一个跨站点脚本警告。 – 2011-03-14 14:10:26
可能重复[jQuery.getJSON不适用于twitter](http://stackoverflow.com/questions/5183831/jquery-getjson-not-working-for-twitter) – epascarello 2011-03-14 14:31:08