Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryajax多个XML文件_Jquery_Xml_Ajax - Fatal编程技术网

jqueryajax多个XML文件

jqueryajax多个XML文件,jquery,xml,ajax,Jquery,Xml,Ajax,下面是我想做的: 我有一系列产品,每个产品都有自己的xml文件,其中包含有关该产品的数据 对于每个产品,我希望在一个div中生成其信息,该div的ID与xml链接中的产品ID相同 html基本上如下所示: <div id="000001" class="product"></div> <div id="000002" class="product"></div> <div id="000003" class="product"><

下面是我想做的:

我有一系列产品,每个产品都有自己的xml文件,其中包含有关该产品的数据

对于每个产品,我希望在一个div中生成其信息,该div的ID与xml链接中的产品ID相同

html基本上如下所示:

<div id="000001" class="product"></div>
<div id="000002" class="product"></div>
<div id="000003" class="product"></div>
到目前为止,我的jquery是:

$(document).ready(function(){

$('.product').each(function(){

    var pId = $(this).attr('id')

    var getURL = "product/" + pId + "/output.xml"

    $.ajax({
        type: "GET",
        url: getURL,
        dataType: "xml",
        success: function(xml) {
            $(xml).find('productinfo').each(function(){

                var title = $(this).find('name').text();
                var url = $(this).find('buyLink href').text();
            });
        }
    });

});
});
我认为我的思路是正确的,但我不确定如何将xml文件中的数据附加到div,或者我的代码是否能够从正确的xml文件中获取数据

如果您能提供任何帮助或建议,我们将不胜感激

$(document).ready(function(){

$('.product').each(function(){

    var pId = $(this).attr('id')

    var getURL = "product/" + pId + "/output.xml"

    $.ajax({
        type: "GET",
        url: getURL,
        dataType: "xml",
        success: function(xml) {
            $(xml).find('productinfo').each(function(){

                var title = $(this).find('name').text();
                var url = $(this).find('buyLink href').text();
            });
        }
    });

});
});