jQuery的的getJSON不工作跨站点 [英] Jquery getJSON Not Working Cross Site

查看:185
本文介绍了jQuery的的getJSON不工作跨站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一块的JavaScript,抓住JSON数据。在本地执行的一切似乎很好地工作。然而,当我试着从不同的站点访问它,这是行不通的。

I have a piece of javascript that grabs JSON data. When executed locally everything seems to work fine. However, when I try accessing it from a different site, it doesn't work.

下面的脚本。

$(function(){
    var aT = new AjaxTest();
    aT.getJson();
});

var AjaxTest = function()
{
    this.ajaxUrl = "http://mydeveloperpage.com/sandbox/ajax_json_test/client_reciever.php";

    this.getJson = function(){
        $.getJSON(this.ajaxUrl, function(data){
            $.each(data, function(i, piece){
                alert(piece);
            });
        });
    }
}

您可以找到完全相同的文件的副本http://mydeveloperpage.com/sandbox/ajax_json_test/。

You can find a copy of the exact same file at "http://mydeveloperpage.com/sandbox/ajax_json_test/".

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

谢谢!

推荐答案

文档

      
  • 由于浏览器的安全限制,大多数Ajax的请求都受到了同样的原产地政策; 请求不能成功地从不同的域,子域,或协议检索数据。

脚本和JSONP请求不受同源策略的限制。

Script and JSONP requests are not subject to the same origin policy restrictions.

您会需要使用 JSONP 让过去同源政策。 jQuery的可以使这种无缝(见上述文档页面的其余部分)。

You're going to need to use JSONP to get past the same-origin policy. jQuery can make this seamless (see the rest of the aforementioned documentation page).

这篇关于jQuery的的getJSON不工作跨站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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