如何使用JQuery解析WordPress的XML提要?

如何使用JQuery解析WordPress的XML提要?,jquery,html,ajax,wordpress,Jquery,Html,Ajax,Wordpress,我试图从同一个域解析和加载XML(来自WordPress),但出现以下错误: 无法加载XMLHttpRequest。飞行前响应中的访问控制允许标头不允许请求标头字段X-Requested-With 奇怪的是,我的html页面位于此处: 我的WordPress xml提要如下: 我的HTML代码是: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit

我试图从同一个域解析和加载XML(来自WordPress),但出现以下错误:

无法加载XMLHttpRequest。飞行前响应中的访问控制允许标头不允许请求标头字段X-Requested-With

奇怪的是,我的html页面位于此处: 我的WordPress xml提要如下:

我的HTML代码是:

<!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Test Document</title>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
    <script type="text/javascript">
    $(document).ready(function(){

        function parse(document){
            $(document).find("item").each(function(){
                $("#content").append(
                    '<br /> Title: '+$(this).find('title').text()+
                    '<br /> Author: '+$(this).find('link').text()+
                    '</p>'
                );
            });
        };

        $.ajax({
            url: 'http://www.knead-nyc.com/articles/feed/', // name of file you want to parse
            headers: {'X-Requested-With': 'XMLHttpRequest'},
            dataType: "xml",
            success: parse,
            error: function(){alert("Error: Something went wrong");}
        });
    });
    </script>

    </head>

    <body>
    <div id="content"></div>
    </body>

</html> 

我做了一些搜索,找到了一个解决方案。虽然我在同一个域(example.com)上,但我得到了以下错误。“无法加载XMLHttpRequest。请求的资源上不存在'Access Control Allow Origin'标头。因此不允许Origin访问”

我发现,有时,同源策略可能会阻止同一域上的子域之间的请求。所以经过几次搜索,我通过在JavaScript中添加document.domain解决了这个问题。例如: document.domain='example.com'

我还将JavaScript的顶部更改为:

$("#loading").show();
                    document.domain = 'example.com'; 
                      $.ajax({
                        type: "GET",
                        url: "/articles/feed/",
            //url will load http://www.example.com/articles/feed/
                        dataType: "xml",
                        success: parseXml
});

我做了一些搜索,找到了一个解决方案。虽然我在同一个域(example.com)上,但我得到了以下错误。“无法加载XMLHttpRequest。请求的资源上不存在'Access Control Allow Origin'标头。因此不允许Origin访问”

我发现,有时,同源策略可能会阻止同一域上的子域之间的请求。所以经过几次搜索,我通过在JavaScript中添加document.domain解决了这个问题。例如: document.domain='example.com'

我还将JavaScript的顶部更改为:

$("#loading").show();
                    document.domain = 'example.com'; 
                      $.ajax({
                        type: "GET",
                        url: "/articles/feed/",
            //url will load http://www.example.com/articles/feed/
                        dataType: "xml",
                        success: parseXml
});