js解析xml

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="../jquery-1.11.2.min.js"></script>
    </head>
    <body>
<div id="shuju"></div>
</body>
<script type="text/javascript">
$.ajax({
    url:"chuli.php",
    dataType:"XML",
    success: function(data){
        var zi = $(data).find("yonghu").children();
        var str = "";
        for(var i=0;i<zi.length;i++)
        {
            //zi.eq(i).find("code").text();
            var name = zi.eq(i).find("name").text();
            str = str+"<div>"+name+"</div>";
        }
        $("#shuju").html(str);
    }
});
</script>
</html>
posted @ 2018-09-19 08:26  net开发人员  阅读(214)  评论(0编辑  收藏  举报