ajax 如何 读取 xml 文档

来源:互联网 发布:安徽移动网络速度慢 编辑:程序博客网 时间:2024/06/07 10:07
<!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 runat="server">    <title></title>    <style type="text/css">    </style>    <script src="jquery-1.8.3.min.js" type="text/javascript"></script>    <script type="text/javascript">        $(document).ready(function () {            $("#Display").click(function () {                $("#message").html('');                $.ajax({                    type: "GET",                    url: "a.xml",                    dataType: "xml",                    success: function (ResponseText) {                        alert(ResponseText);                        var table = "<table border='1px'><tr><td>firstname</td><td>lastname</td><td>city</td></tr>";                        $(ResponseText).find('friend').each(function () {                            var first = $(this).find('firstName').text();                            var last = $(this).find('lastName').text();                            var city = $(this).find('city').text();                            table += "<tr><td>" + first + "</td><td>" + last + "</td><td>" + city + "</td></tr>";                        })                        table += "</table>";                        $("#message").append(table);                    }                });            });        });    </script></head><body>    <form id="form1" runat="server">    <label>Display My Friends</label><br />  <input type="button" value="Display" id="Display" />  <div id="message"></div>    </form></body></html>
<?xml version="1.0" encoding="utf-8" ?><friends>    <friend>        <name>            <firstName type="aa">Guo</firstName>            <lastName>Hu</lastName>        </name>        <address>            <province>Shanghai</province>            <city>PuDong</city>        </address>    </friend>    <friend>        <name>            <firstName type="bb">Lei</firstName>            <lastName>Hu</lastName>        </name>        <address>            <province>hubei</province>            <city>xiantao</city>        </address>    </friend></friends>
0 0