21,886
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title> jquery demo </title>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function show(){
$.get( "server.php", function(data) {
$('#txt').html(data.content);
}, "json" );
}
</script>
</head>
<body>
<p>這裡不會被刷新</p>
<div id="txt">原來內容</div>
<input type="button" value="刷新內容" onclick="show()">
</body>
</html>
server.php
<?php
$ret = array();
$ret['content'] = '新內容';
echo json_encode($ret);
?>
<script src="jquery.min.js" type="text/javascript"></script>
<script>
$(function(){
$("#reload").click(function(){
$.ajax({
type:"POST",
url:"reload.php",
success:function(msg){
if(msg) {
$("#div1").html(msg);
}
}
});
});
});
</script>
<BODY>
<div id="div1" style="float:left;width:400px;line-height:30px;margin:100px auto;">从前有座山!</div>
<div style="width:100px;height:100px;"><input type="button" name="reload" id="reload" value="刷新" /></div>
</BODY>
reload.php页面
<?php
echo "刷新之后";
?>
只是这么个简单例子。