Problem using $ .getJSON () with jQuery

I am trying to run the following:

$.getJSON('http://services.digg.com/2.0/story.getTopNews?limit=25&callback=?', function(data) {
    console.log(data);
});

But I get:

story.getTopNews: -1Resource is interpreted as Script, but passed with the MIME type application / json. story.getTopNews: 2Uncaught SyntaxError: Unexpected token:

I also tried something like this:

var url = "http://services.digg.com/2.0/story.getTopNews?limit=25";

$.ajax({
    url: url,
    crossDomain:true,
    dataType: "json",
    success:function(data,text,xhqr) {
        console.log(data);
    }
});

I get this:

XMLHttpRequest cannot load http://services.digg.com/2.0/story.getTopNews?limit=25 . The origin of http://sumews.com is not permitted by Access-Control-Allow-Origin. services.digg.com/2.0/story.getTopNews?limit=25GET http://services.digg.com/2.0/story.getTopNews?limit=25 undefined (undefined)

Any help would be greatly appreciated.

+3
source share
1 answer

AJAX . , .

- JSONP. , script , script. script , . script (, , digg), JSONP.

JSON ( JSONP), , Javascript. .


, digg JSONP, type=javascript:

$.getJSON('http://services.digg.com/2.0/story.getTopNews?limit=25&type=javascript&callback=?', function(data) {
    console.log(data);
});

This works for me.

+4
source

All Articles