<!--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遇到了不认识的标签,直接显示标签子元素,略过对标签的解析.??