开发者

Loading json from different domain?

开发者 https://www.devze.com 2023-02-27 13:58 出处:网络
Is there any way to load the json provided by the http://search.twitter.com/search.json URL on to my page via ajax? Everything I\'ve tried gives me:

Is there any way to load the json provided by the http://search.twitter.com/search.json URL on to my page via ajax? Everything I've tried gives me:

XMLHttpRequest cannot load http://search.twitter.co开发者_如何学Cm/search.json. Origin null is not allowed by Access-Control-Allow-Origin.

If not, then whats the point of having such services in the first place?W


Use JSONP, or JSON with padding:

<script type = "text/javascript">
    window.getTwitterResults = function(data) {
      console.log(JSON.stringify(data));
    };
</script>
<script type = "text/javascript" src = "http://search.twitter.com/search.json?q=cheese&callback=getTwitterResults"></script>
0

精彩评论

暂无评论...
验证码 换一张
取 消