我正在開發一個網站,它從模板頁面加載html,然後從XML加載內容。例如在文檔中調用這些函數.ready函數谷歌瀏覽器 - 失敗GET ajax請求
$.ajax({
type : "GET",
url : "template.html",
dataType : "html",
success : function(html) {
var ndoc = document.createElement('html');
ndoc.innerHTML = html;
page = $('body', ndoc);
$('body').html(page.html());
$.ajax({
type : "GET",
url : "XML/content.xml",
dataType : "xml",
success : function(xml) {
page = $(xml).find('chisiamo').find('dialogue')[0];
setupPage(page);
}
});
}
});
這適用於Firefox和Safari。但在Chrome中,當它嘗試加載template.html時,我得到'原始null不被Access-Control-Allow-Origin'允許。我怎麼解決這個問題?非常感謝你。
您能否顯示一個截圖? – zerkms 2012-03-07 20:44:48
截圖?這是我在Chrome控制檯中得到的確切字符串:'XMLHttpRequest無法加載file:///Users/***/Dropbox/CorpoMusicale/template.html。 Origin-null不被Access-Control-Allow-Origin允許。' – Lorenzo 2012-03-07 20:46:53
你見過:http://stackoverflow.com/questions/5224017/origin-null-is-not-allowed-by-access-control-allow-origin-in-chrome-why – Igor 2012-03-07 20:49:10