jQuery解析JSON URL

时间:2013-02-06 16:19:32

标签: jquery json

我正在尝试从输出以下JSON数据的URL获取JSON数据:

[
 {
    "belief_desc":"Jesus Died For Your Sins",
    "0":"Jesus Died For Your Sins"
 },
 {
    "belief_desc":"People Are Sinful",
    "0":"People Are Sinful"
 },
 {
    "belief_desc":"God Loves You",
    "0":"God Loves You"
 },
 {
    "belief_desc":"We Must Receive Christ",
    "0":"We Must Receive Christ"
 }
]

(注意:它仅在此问题中格式化以便于阅读。)

现在我正在尝试使用这个简单的jQuery脚本解析它:

<script>
    var url = "http://mySite.com/data.json";
    $.getJSON(url, function(data){
        alert(data);
        });
</script>

我没有从URL获取数据,因为警报不会显示。关于为什么这不起作用的任何想法?

1 个答案:

答案 0 :(得分:4)

跨域你无法做简单的JSON。

Basic how-to for cross domain jsonp

阅读跨域请求。