PHP编程实战15-11

<!--PHP编程实战-->
<!--JSON & Ajax -->
<!--15-11-->
<!--使用jQuery在加载页面后修改p元素-->
<html>
<head>
    <title>Loading Plain Text with jQuery</title>
    <style type="text/css">
        #generated_content{
            border: 1px solid black;
            width: 300px;
            background-color: #dddddd;
        }
    </style>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax(
                {
                    type: "get",
                    url: "animals.xml",
                    dataType: "text",
                    success: function (data) {
                        $("#generated_content").html("<pre>" + data + "</pre>");
                    },
                    failure: function () {
                        $("#generated_content").html("An error has occured making the request");
                    }
                }
            )
        })
    </script>
</head>
<body>
<p><strong>Ajax grabbed plain text:</strong></p>

<div id="generated_content"> </div>
</body>
</html>

xml数据文件

<!--animals.xml-->
<animals>
    <dogs>
        <dog>
            <name>snoopy</name>
            <color>brown</color>
            <breed>beagle cross</breed>
        </dog>
        <dog>
            <name>jade</name>
            <color>black</color>
            <breed>lab cross</breed>
        </dog>
    </dogs>
    <cats>
        <cat>
            <name>teddy</name>
            <color>brown</color>
            <breed>tabby</breed>
        </cat>
    </cats>
</animals>

重点

  • 使用了jQuery这样的高级API
  • xml文本直接插入dom,相当于html遇到了不认识的标签,直接显示标签子元素,略过对标签的解析.??
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容