如何用php+ajax实现页面的局部刷新 phpajaxjs数据库 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用户完后完成输入提交,如果成功,就把提交的内容追加到评论列表。具体可以查看ajax使用,以及与php交互。 你到网上搜下,ajax异步提交数据,很多案例的,或者直接到jquery官网看使用方法 要刷新的页面<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页面<?phpecho "刷新之后";?>只是这么个简单例子。 client.html<!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);?> 关于PHP函数声明与调用的一个小问题 php调用系统命令的问题 請問怎樣才能用php顯示.swf flash檔呢? 无法显示图片的问题 求一个mysql查询统计语句 php 导出excel格式 哦,吐血提问:Apache 和MySQL应该怎样读才是正确的呢?谢谢了! 如何用程序改变文件夹属性,怎么不行呢!(在线等待!) 百度LBS的API根据IP定位地理位置的sn算法 一台服务器多个域名泛解析 CSS中设置的部分参数link后无法读取使用 svn被防火墙拦截
具体可以查看ajax使用,以及与php交互。
<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 "刷新之后";
?>只是这么个简单例子。
<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);?>