首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

请哪位大神写一下ajax的get方式和post方式的写法解决办法

2012-04-17 
请哪位大神写一下ajax的get方式和post方式的写法比如各自传送一个数据1到test.jsp他们的写法是????我对get

请哪位大神写一下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);  } 

热点排行