如何通过Jquery加载2个xml文件?

时间:2013-10-22 22:50:49

标签: jquery xml

我有2个xml文件(data.xml和images.xml)加载到div结构中,如:

<div class="listing">
    <div class="listing-image"></div>
    <div class="listing-data"></div>
</div>

如何将它们一起装入?这是data.xml

<dealer id="123">
    <name>Lily's Trucks</name>
</div>
<dealer id="456">
    <name>Ali's Trucks</name>
</div>
<dealer id="789">
    <name>May's Trucks</name>
</div>

和images.xml

<images>
    <image source="/image1.jpg" id="123"/>
    <image source="/image2.jpg" id="456"/>
    <image source="/image3.jpg" id="789"/>
</images>

输出应为:

<div class="listing">
    <div class="listing-image"><img src="/image1.jpg"/></div>
    <div class="listing-data">Name: Lily's Trucks</div>
</div>
<div class="listing">
    <div class="listing-image"><img src="/image2.jpg"/></div>
    <div class="listing-data">Name: Ali's Trucks</div>
</div>
<div class="listing">
    <div class="listing-image"><img src="/image3.jpg"/></div>
    <div class="listing-data">Name: May's Trucks</div>
</div>

干杯。

1 个答案:

答案 0 :(得分:0)

使用jquery.load()

<script>
    $(function(){
        $('.listing-image').load('http://images.xml');
        $('.listing-data').load('http://data.xml');
    });
</script>


<div class="listing">
    <div class="listing-image"></div>
    <div class="listing-data"></div>
</div>