叶子的小屋
ajax,XMLHttpRequest对象
2015-8-14 admin


//对象创建



var xmlHttp;


function createXMLHttpRequest()

{

   if(window.ActiveXObject)

   {

      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

   }

   else if(window.XMLHttpRequest)

   {

      xmlHttp = new XMLHttpRequest();

   }



}







//使用



function AddNumber()

{

  createXMLHttpRequest();

  var url= "http://127.0.0.1";

  xmlHttp.open("GET",url,true);

  xmlHttp.onreadystatechange=ShowResult;

  xmlHttp.send(null);

}







function ShowResult()

{

   if(xmlHttp.readyState==4)

   {

      if(xmlHttp.status==200)

      {

          document.getElementById("sum").value=xmlHttp.responseText;

      }

   }

}