2011-08-25 83 views
0

有誰知道如何解決這個錯誤?我正在使用jquery 1.6.2XMLHttpRequest無法加載http://www.reddit.com/.xml

XMLHttpRequest無法加載http://www.reddit.com/.xml。來源null爲 Access-Control-Allow-Origin不允許。

$(document).ready(function() { 
    $.ajax({ 
     type: "GET", 
     url: "http://www.reddit.com/.xml", 
     dataType: "xml", 
     crossDomain: true, 
     success: xmlParser 
    }); 

    // ... 
}); 
+0

簡而言之,'crossDomain'不能用xml開箱即用,但它_does_可以與JSONP一起工作。使它與XML協同工作需要一些額外的工作。 –

+0

[需要幫助使用JavaScript獲取跨域XML]的可能重複(http://stackoverflow.com/questions/1550839/need-help-with-getting-cross-domain-xml-with-javascript) – Quentin

+0

嗨,我同意雷,請參閱以下網頁以獲取更詳細的信息:http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/關注 – Neil

回答

1

使用zrssfeed它會讓你的生活變得更加簡單,jsFiddle

$('#test').rssfeed('http://www.reddit.com/.xml'); 
0

其因爲same-origin-policy創建一個服務器端代理和有代理查詢的Web服務,並返回你的Ajax請求的XML響應

相關問題