JSON API 不会在 jquery getJSON 中返回任何结果

json api doesnt return any results in jquery getJSON

本文关键字:返回 任何 结果 getJSON jquery API JSON      更新时间:2023-09-26

我正在尝试从他们公司API文档中的此示例JSON文件中提取信息。但它不会返回任何结果:(

http://jsfiddle.net/28hEb/21/

$.getJSON("http://api.8coupons.com/v1/getcategory", function (data) {
    $.each(data, function (index, item) {
        $("<div>").html(item.category).appendTo("#content");
        if (index == 3) {
            return false;
        }
    });
});

?callback添加到 url 中,以便 getJSON 执行 jsonp 请求而不是 ajax/cors/json。

http://api.8coupons.com/v1/getcategory?callback=?

http://jsfiddle.net/Tentonaxe/28hEb/22/

对不同的域使用callback parameter

$.getJSON("http://api.8coupons.com/v1/getcategory?callback=?", function (data) {
    $.each(data, function (index, item) {
        $("<div>").html(item.category).appendTo("#content");
        if (index == 3) {
            return false;
        }
    });
});

另请阅读同源策略和 JSON 到 JSONP-绕过同源策略