读书人

请哪位大神写一下ajax的get方式和post

发布时间: 2012-04-17 15:06:33 作者: rapoo

请哪位大神写一下ajax的get方式和post方式的写法
比如各自传送一个数据1到test.jsp

他们的写法是????

我对get还了解一些

没用过post发送


这是get方式,post方式不会写

JScript code
var xmlhttp;  if(window.ActiveXObject)  {      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }  else  {      xmlhttp=new XMLHttpRequest();  }  function senddata()  {      serverpage="test.jsp?data=1";      xmlhttp.open("GET",serverpage);      xmlhttp.onreadystatechange=function()      {          if(xmlhttp.readyState==4&&xmlhttp.status==200)          {              document.getElementById("msg").innerHTML=xmlhttp.responseText;          }      }      xmlhttp.send(null);  }  


[解决办法]
JScript code
var xmlhttp;  if(window.ActiveXObject)  {      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }  else  {      xmlhttp=new XMLHttpRequest();  }  function senddata()  {      serverpage="test.jsp";    data = 'data=1'    xmlhttp.onreadystatechange=function()      {          if(xmlhttp.readyState==4&&xmlhttp.status==200)          {              document.getElementById("msg").innerHTML=xmlhttp.responseText;          }      }     xmlhttp.open("POST",serverpage);    xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;');    xmlhttp.send(data);  } 

读书人网 >JavaScript

热点推荐