The following is a relatively complete code that can be used in practical applications. This code is ajax Implemented in combination with php code.
1.ajax code is as follows:
<!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> 当前页面数据库中访问次数:<div id='num'></div> <input type="button" value="增加次数" > </body> </html>
2.php code:
<?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']; } ?>
The above is the entire content of this article, I hope you all like it.