+ -
当前位置:首页 → 问答吧 → [求助] jquery读取xml

[求助] jquery读取xml

时间:2010-01-14

来源:互联网

我把该html和jquery和xml文件放在一块,源码如下:

test1.html

<html>
<head>
    <meta http-equiv="Content-Type" content="application/xml">
    <title>test</title>
    <script type='text/javascript' src='jquery-1.3.1.min.js'></script>
   
    <script type='text/javascript'>
        jQuery().ready(function(){
            $.ajax({
                url:'student.xml',
                dataType: 'xml',
                error: function(xml){
                    $('#show').text('Error loading XML document'+xml);
                },
                success: function(xml){
                    $('#show').text('Success loading XML document'+xml);
                }
            });
        })
    </script>
</head>
<body>       
    <div id='show'></div>
</body>
</html>


student.xml:

<?xml version="1.0" encoding="UTF-8"?>
<stulist>
        <student email="mailto:[email protected]" target="_blank>[email protected]"> 
            <name>zhangsan</name>
            <id>1</id>
        </student>
        <student  email="mailto:[email protected]" target="_blank>[email protected]">
             <name>lisi</name>
             <id>2</id>
        </student>
</stulist>

结果输出:
test        jQuery().ready(function(){            $.ajax({                url:'student.xml',                dataType: 'xml',                error: function(xml){                    $('#show').text('Error loading XML document'+xml);                },                success: function(xml){                    $('#show').text('Success loading XML document'+xml);                    /*                    $(xml).find("student").each(function(){                        var id=$(this).children("id");   //鍙栧?璞?                        var id_value=$(this).children("id").text();  //鍙栨枃鏈?鎴栬
[ 此帖被zchhz在2010-01-16 11:41重新编辑 ]

作者: zchhz   发布时间: 2010-01-14

相关阅读 更多