zoukankan      html  css  js  c++  java
  • 【学习笔记】ajax处理XML文件方法

    HTML源文件

    <!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" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>demo5</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script>
    $(function(){
        $('input').click(function() {
            var ul = $('#info>ul');
            $.ajax({
                url:'demo5.php?'+Math.random(),
                type:'get',
                dataType:'xml',
                success:function(xml){
                    $(xml).find('title').each(function(){
                        // $(this).text();
                        ul.append('<li>'+$(this).text()+'</li>')
                    });
                }
            });
        });
    });
    </script>
    </head>
    <body>
        <input type="button" value="获取新闻列表" />
        <div id="info">
            <ul></ul>
        </div>
    </body>
    </html>

    PHP源文件

    <?php
        header('Content-type:text/xml;charset=utf-8');
    
        $str = "<root>
                    <title>否认放松计划生育政策</title>
                    <title>劳教制度简史</title>
                    <title>中共中央决定废止劳教制度</title>
                </root>";
        echo $str;
    ?>
  • 相关阅读:
    百度搜索技巧
    phpstorm知识点
    A-Z
    边框
    display
    布局
    盒模型
    浮动
    字体与图标
    pselect 问题
  • 原文地址:https://www.cnblogs.com/littlefly/p/3661678.html
Copyright © 2011-2022 走看看