AJAX页面局部调用

<script>
function gb2utf8(data){
 var glbEncode = [];
 gb2utf8_data = data;
 execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
 var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(.{2})(.{2})/g,"%$2%$1").replace(/%([A-Z].)%(.{2})/g,"@$1$2");
 t=t.split("@");
 var i=0,j=t.length,k;
while(++i<j) {
 k=t[i].substring(0,4);
 if(!glbEncode[k]) {
  gb2utf8_char = eval("0x"+k);
  execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
  glbEncode[k]=escape(gb2utf8_char).substring(1,6);
  }
  t[i]=glbEncode[k]+t[i].substring(4);
 }
 gb2utf8_data = gb2utf8_char = null;
 return unescape(t.join("%"));
}
function ajaxSubmit2(){
 document.getElementById("loginstate").innerHTML = "<center><img src='images/load01.gif'></center>";
 //创建XMLHttpRequest对象
 var xmlhttp;
 try{
  xmlhttp=new XMLHttpRequest();
 }catch(e){
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
  xmlhttp.onreadystatechange=function(){
   if (4==xmlhttp.readyState){
    if (200==xmlhttp.status){
     var content=gb2utf8(xmlhttp.responseBody);
     document.getElementById("loginstate").innerHTML = content;
    }else{
    alert("error");
    }
   }
  }
 //打开连接,true表示异步提交
 xmlhttp.open("post","time.php?id=1", true);
 //当方法为post时需要如下设置http头
 xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
 //发送数据
 xmlhttp.send(null);
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<div id="loginstate"></div>
<script language="javascript">ajaxSubmit2();</script>
</body>
</html>

 

你可能感兴趣的:(Ajax)