AJAX 核心三部曲

 

  1. 〈script lanuage = "javaScript"〉  
  2. //創建對象  
  3. function createXMLHttpRequest(){  
  4. if(window.ActiveXObject){  
  5. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
  6. }  
  7. else if(window.XMLHttpRequest){  
  8. xmlHttp = new XMLHttpRequest();   
  9. }  
  10. }  
  11. //前臺界面事件調用的函數  
  12. function checkName(){  
  13. createXMLHttpRequest();   
  14. xmlHttp.onreadystatechange = handleStateChange;   
  15. var sql = "UserReg.aspx?";   
  16. xmlHttp.open("GET",sql,true);   
  17. xmlHttp.send(null);   
  18. }  
  19. //和服務器交互期間執行的函數  
  20. function handleStateChange(){  
  21. if(xmlHttp.readyState == 4){  
  22. if(xmlHttp.status == 200){   
  23. document.getElementById("divx").innerHTML = xmlHttp.responseText;   
  24. }  
  25. }  
  26. }  
  27. 〈script〉  

 

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