Ajax

<script language="javascript">
<!--
function ajaxSubmit(){
  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 str = xmlHttp.responseText;
  alert("成功");
   }
   else{
     alert("失敗");
   }
 }
  }
 
  xmlHttp.open("post","ajax.aspx",true);
  //post時才設的HTTP頭
  xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
  xmlHttp.send("title="+escape(title));
}

/*************二**************************/ 
var xmlHttp;
function GetXmlHttp(handler){
  var objXmlHttp;
  try{
     xmlHttp = new XMLHttpRequest();
  }
  catch(e){
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  objXmlHttp.onreadystateChange = handler;
  return objXmlHttp;
}
function stateChange(){
  if(4 == xmlHttp.readyState){
   if(200 == xmlHttp.Status){
     var str = xmlHttp.responseText;
  alert("成功");
  document.getElementById("a").innerHTML = xmlHttp.responseText;
   }
   else{
     alert("失敗");
   }
   }  
}

function showHint(str){
  if(str.Length > 0){
    xmlHttp = GetXmlHttp(stateChange);
 xmlHtp.open("Get","register.aspx",true);
 xmlHttp.send(null);
  }
  else{
    document.getElementById("a").innerHTML = "";
  }
}  
//-->
</script> 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章