下面就分享一段相对完整的能够在实际应用中派上用场的代码,此代码是ajax结合php代码实现的。
一.ajax代码如下:
<!doctype html><html><head><meta charset=" utf-8"><title>ajax实现浏览量点击增加</title><script type="text/javascript">var xmlhttp=false;function add(){ try{ xmlhttp= new xmlhttprequest; } catch(e){ xmlhttp= new activexobject("microsoft.xmlhttp"); } xmlhttp.open('get','count.php?a=a',false); xmlhttp.onreadystatechange=func; xmlhttp.send(null);} function func(){ if(xmlhttp.readystate==4){ var msg=xmlhttp.responsetext; var tt=document.getelementbyid("num"); tt.innerhtml=msg; }}</script></head><body>当前页面数据库中访问次数:<p id='num'></p><input type="button" value="增加次数" ></body></html>
二.php代码:
<?php mysql_connect('localhost','root',''); mysql_selectdb('click'); $rs=mysql_query("update click set num = num +1 where name = '".$_get['a']."'"); if(mysql_affected_rows()==1){ $rs=mysql_query("select * from click where name='".$_get['a']."'"); $row=mysql_fetch_array($rs); echo $row['num']; }?>
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
php针对数据库的读取、判断及session登陆的使用方法
php文件上传所涉及的文件与表单操作及数据库操作
php针对错误处理的常用技巧
以上就是php+ajax实现浏览量点击增加的详细内容。