Tôi có mã này và tôi đang cố trả lại API Flickr, tuy nhiên tôi nhận được lỗi sau.Flickr JSON trả lại lỗi trong miền chéo JavaScript
Cross-Origin Yêu cầu Bị chặn: The Origin Policy Same không cho phép đọc tài nguyên từ xa tại
http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback={callback}&tags=london&tagmode=any&format=json
. Điều này có thể được khắc phục bằng cách di chuyển tài nguyên đến cùng một miền hoặc bật CORS.
Làm cách nào để kích hoạt tính năng này trong mã của tôi?
enter
MyFeed.prototype.getFeed = function(data) {
console.log(f.feedUrl);
var request = new XMLHttpRequest();
request.open('GET', f.feedUrl, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
console.log(request.responseText);
var data = JSON.parse(request.responseText);
} else {
// We reached our target server, but it returned an error
console.log("error");
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
}here
Tôi đã có cùng một câu hỏi 5 năm trước câu trả lời là sử dụng JSONP http://api.jquery.com/jquery.getjson/ với jquery. http://stackoverflow.com/questions/3112399/prototype-flickr-ajax-request-doesnt-work-with-firefox – ncubica