我試圖用deezer api來查找藝術家,並使用Jquery顯示他們的名字和圖像。這是我的代碼:如何使用Deezer Api?
$.getJSON('http://api.deezer.com/search/artists?q='+q+'',
function(data) {
$("#artists").empty();
$.each(data, function(i,item){
var y=item.picture;
var z=x+y;
$("#artists").append("<div id='card_artist'><div id='cardimg' style='background-image: url("+ z +");'></div><div id='artistname' class='jtextfill'><span>" + item.name + "<span></div></div>");
});
});
但它只是不會工作。代碼看起來很好,但它一直扔了此錯誤消息,我卻沒有一個關於線索或如何解決:
XMLHttpRequest cannot load http://api.deezer.com/search/artists?q=whatever. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
我如何得到它的工作?
啊!!! * facepalm *我以錯誤的方式去討論它......我完全忘記了JSONP,感謝你清除它! – looserlf