DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> AJAX入門 >> AJAX詳解 >> AJAX向後台傳參數
AJAX向後台傳參數
編輯:AJAX詳解     
function createXMLHttpRequest(){
   if(window.ActiveXObject)
   {
     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
   else if(window.XMLHttpRequest)
   {
     xmlHttp = new XMLHttpRequest();
   }
  }
 
  function createQueryString()
  {
   var firstName = document.getElementById("firstName").value;
   var middleName = document.getElementById("middleName").value;
   var birthDay = document.getElementById("birthDay").value;
   var queryString = "firstName="+ firstName +"&middleName="+middleName+"&birthDay="+birthDay;
   return queryString;
  }
 
  function doRequestUsingGet(){
   createXMLHttpRequest();
  
   var queryString = "WebForm2.ASPx?";
   queryString  = queryString + createQueryString() + "&timeStamp="+new Date().getTime();
   XMLHttp.onreadystatechange = handleStateChange;
   XMLHttp.open("GET",queryString,true);
   XMLHttp.send(null);
  }
 
  function doRequestUsingPost(){
   createXMLHttpRequest();
  
   var url   = "WebForm2.ASPx?timeStamp="+new Date().getTime();
   var queryString = createQueryString();
   XMLHttp.open("POST",url,true);
   XMLHttp.onreadystatechange = handleStateChange;
   XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   XMLHttp.send(queryString);
  }
 
  function handleStateChange(){
  
   if(XMLHttp.readyState == 4)
   {
    if(XMLHttp.status == 200)
    {
    
     parseResults();
    }
   }
  }
 
  function parseResults(){
   var responseDiv = document.getElementById("serverResponse");
   var testStr = XMLHttp.responseText;
   document.getElementById("firstName").value = testStr;
     }
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved