Ajax基礎学習(二)--要求方式(post/get)

1381 ワード


.......
function createQueryString(){
 var firstName = document.getElementById("firstName").value;
 var secName = document.getElementById("secName").value;

 var querystring="firstName="+firstName+"&secName="+secName;
}


//GET  
function doRequestUsingGET(){
   createXMLHttpRequest();
   var queryString = "test.php?";
   queryString= queryString + createQueryString()+"&timstamp="+new Date().getTime();
   Ajax.onreadystatechange=handleStateChange;
   Ajax.open("GET",queryString,true);
   Ajax.send(null);

}

//POST  
function doRequestUsingPOST(){
   createXMLHttpRequest();

  /*        GET      */
   var url= "test.php?timstamp="+new Date().getTime();
   var queryString=createQueryString();3
   Ajax.open("POST",url,true);
   Ajax.onreadystatechange=handleStateChange;
   Ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded")
  
   Ajax.send(queryString);

}

function handleStateChange(){
    if(Ajax.readyState==4){
       if(Ajax.status==200){ .......}   //        
    }

}



......