Hasan Alaca
Hasan Alaca

Reputation: 232

json api doesnt return any results in jquery getJSON

I'm trying to pull info from this sample JSON file in their company API documentation. But it's not returning any results :(

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;
        }
    });
});

Upvotes: 1

Views: 76

Answers (2)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Use a callback parameter for different domain,

$.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;
        }
    });
});

Also read the same origin policy and JSON-to-JSONP-Bypass-Same-Origin-Policy

Upvotes: 2

Kevin B
Kevin B

Reputation: 95022

Add ?callback to the url so that getJSON performs jsonp request rather than ajax/cors/json.

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

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

Upvotes: 6

Related Questions