Home  >  Article  >  Web Front-end  >  Code example of adding 1 to the number of clicks implemented by ajax_html/css_WEB-ITnose

Code example of adding 1 to the number of clicks implemented by ajax_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:55:481141browse

Code example of adding 1 to the number of clicks implemented by ajax:
In the code example of clicking a button to achieve the effect of increasing the number, it is introduced how to click the button to achieve the effect of increasing the number by 1, but it does not seem to work It has no practical use. Here I will share a relatively complete code that can be used in practical applications. This code is implemented by ajax combined with php code.
1.ajax code is as follows:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</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'];  }?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn