当运行此脚本时,它将错误视为跨源请求被阻止:同源策略禁止在http://api.learnsocial.com/learnsocial/ad-placeholder?ref=EG0tF4__&aid=2读取远程资源。 (原因:CORS标题'Access-Control-Allow-Origin'丢失)。任何人都可以帮我解决这个问题。
<script > $(function() {
var adAPI = "http://api.learnsocial.com/learnsocial/ad-placeholder?ref=EG0tF4__&aid=2";
$.support.cors = true;
$.getJSON(adAPI).done(function(data) {
var adt, src, lurl, h, w;
$.each(data, function(key, value) {
if (key === "at") {
adt = value;
} else if (key === "lu") {
lurl = value;
} else if (key === "ip") {
src = value;
} else if (key === "iw") {
w = value;
} else if (key === "ih") {
h = value;
}
});
document.write("<a href=" + lurl + " target='\_blank\'><img src=" + src + " width=" + w + " height=" + h + " alt=" + adt + " border='\0\' ></a>");
}).fail(function(d) {
alert(JSON.stringify(d));
});
});</script>