前提:电脑上已经安装了AppServ
代码如下:
第一个页面,只写HTML代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>第一个ajax</title>
</head>
<body>
<div class="comment">
<h6>zhangsan:</h6>
<p class="para">soft</p>
</div>
<div class="comment">
<h6>李四:</h6>
<p class="para">板凳</p>
</div>
<div class="comment">
<h6>王五:</h6>
<p class="para">地板</p>
</div>
</div>
<script src="../libs/jquery.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<input type="button" id="send" value="Ajax获取">
<div class="comment">已有评论:</div>
<div id="resText"></div>
<script src="../libs/jquery.js"></script>
<script>
$(function () {
$("#send").click(function () {
/* $("#resText").load("firstajax.html"); //将firstajax页面整个内容加在id为restext中*/
/* $("#resText").load("firstajax.html .para"); //将firstajax页面中class为para的内容加在restext中*/
});
});
</script>
</body>
</html>