jquery从xml数据中弹出库

时间:2012-04-13 12:13:43

标签: javascript jquery html

我在我的HTML页面中添加了head标记

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>

<script type="text/javascript">
$(function () {
       $.ajax({
                type: "GET",
                url: "AllResponse.xml", // replace with absolute URL of your gallery's xml file
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('Hotel').each(function() {

                       var url = $(this).find('HotelFrontImage').attr('Url');



                        $('<li></li>').html('<a href="'+url+'" target="_parent"><img src="'+url+'"/></a>').appendTo('#gallery');
                    });

                }

            });

});
</script>

并给出了身体标签

但它没有显示在jquery

中弹出

请告诉我我的代码中究竟出现了什么问题

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('body').append($('<ul />', { 'id': 'gallery' }));

            var xml = $.parseXML('<Hotels><Hotel id="1"><Name>Taj 1</Name><HotelFrontImage Url="https://lh5.googleusercontent.com/-y301Ju4n32g/TRCtzBfoiZI/AAAAAAAAABc/3tGEuAD3R8I/w487-h365-k/51.jpg"></HotelFrontImage>'
                              + '</Hotel><Hotel id="2"><Name>Taj 2</Name><HotelFrontImage Url="https://lh3.googleusercontent.com/-ZkMSKCbY0Y8/TRCpCX5p35I/AAAAAAAAABQ/ZL2nsL-ir7U/s277/3.jpg"></HotelFrontImage>'
                              + '</Hotel><Hotel id="3"><Name>Taj 3</Name><HotelFrontImage Url="https://lh5.googleusercontent.com/-y301Ju4n32g/TRCtzBfoiZI/AAAAAAAAABc/3tGEuAD3R8I/s800/51.jpg"></HotelFrontImage></Hotel></Hotels>');

            $(xml).find('Hotel').each(function () {
                var Url = $(this).find('HotelFrontImage').attr('Url');
                $('<li></li>').html('<a href="' + Url + '" target="_parent"><img src="' + Url + '"/></a>').appendTo('#gallery');
            });
        });
    </script>
</head>
<body>
</body>
</html>