日期:2014-05-16  浏览次数:20747 次

求助:基于Ajax技术用javascript和html编写一段代码
新手求助:基于Ajax技术用javascript和html编写一段代码,用下拉菜单来动态读取服务器上xml文件内容并显示在屏幕上。多谢大家指点!

<xml>
<employee>
<name>Norstar Times</name>
<location>Beijing</location>
<num>10</num>
</employee>
<employee>
<name>Norstar Media</name>
<location>Shaihai</location>
<num>10</num>
</employee>
</xml>
Ajax xml javascript html

------解决方案--------------------
<script src="http://www.coding123.net/js/jquery.js"></script>
<script>
    $.ajax({
        dataType: 'xml',
        url: 'x.xml',//xml文件路径
        cache: false,
        success: function (dom) {
            var name, location, num;
            $('employee', dom).each(function () {
                name = $('name', this).text();
                location = $('location', this).text();
                num = $('num', this).text();
                alert(name + '\n' + location + '\n' + num);
            });
        },
        error: function (xhr) { alert('xml路径有问题~\n' + xhr.responseText); }
    });
</script>


上面是jq的,底层的参考这个:javascript xml