$(document).ready(function() {
$(function() {
url = 'http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml?fmt=xml';
$.ajax({
type: "GET",
url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
dataType: 'json',
error: function() {
alert('Unable to load feed, Incorrect path or invalid feed');
},
success: function (xml) {
values = xml.responseData.feed.entries;
$.each(values, function (i) {
$('#results').append('<h1>' + values[i].title + '</h1>');
$('#results').append(values[i].content);
});
}
});
});
});
上面的代碼在我jsfiddle工作正常 - 但實施時,它始終轉到錯誤alert()
功能的jQuery/AJAX飼料解析器腳本
我的控制檯報告:(報告下面的本地和現場服務器)
XMLHttpRequest無法加載http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml?format=xml。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此不允許原產地'null'訪問。 home.html:1 XMLHttpRequest無法加載http://bsnm.s3.amazonaws.com/IVC/103b8b081e0c4ee0ef0d57d45ed11104。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此不允許原產地'null'訪問。
你可以給錯誤函數添加一個'err'參數並提醒'err.message'嗎? –
是'document.location.protocol'' https:'? – guest271314