一小段JS代码实现静态页面点击数的自动更新(使用AJAX)

 

< script language = " javascript " >
var  xmlHttp;
if  (window.ActiveXObject) {
   xmlHttp
=new ActiveXObject("Microsoft.XMLHTTP");
}

else   if  (window.XMLHttpRequest) {
   xmlHttp
=new XMLHttpRequest();
}

var  now  =   new  Date(); 
var  num = now.getYear() + now.getMonth() + now.getDay() + now.getHours() + now.getMinutes() + now.getTime()

var  url = " /MLXZ/Click.aspx?id=306& " + num;
xmlHttp.open(
" GET " ,url, true );
xmlHttp.onreadystatechange
= yang;
xmlHttp.send(
null );

function  yang()
{
if(xmlHttp.readyState==4){
  
if(xmlHttp.status==200){
    
var mes= xmlHttp.responseText;
    document.getElementById(
"Click").innerHTML=mes;
  }

}

}

</ script >

click.aspx为动态页面,实现功能为更新接收ID的点击数,并返回, 在网页中要有一个名为Click的层

你可能感兴趣的:(Ajax)