A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 天行 中级黑马   /  2013-3-16 07:08  /  1643 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

AJAX异步刷新post提交表单和get提交表单的区别,还有具体的代码是怎么写的?


1 个回复

倒序浏览
区别:
1)从浏览器提交数据的方式不同post是把数据放在报文体里面的,而get是把数据放在报文头的URL后面的
2)从服务器端获取数据一般用GET方式,比如:分页,而POST请求一般用于提交数据不返回数据的,比如:增,删除,更新等操作都采用POST方式
代码如下:
Get请求代码如下:
var xhr=new XMLHttpRequest();
xhr.open("GET","Login.aspx?Uname="+name,true);
xhr.setHeaderRequest("If-Modified-Since","0");
xhr.onreadystatechange=function(){
   if(xhr.readyState==4){
      ifif(xhr.status==200){
          document.getElemetById("div1").innerHTML=xhr.responseText;
       }
   }
}
xhr.send(null);
post请求代码如下:
var xhr=new XMLHttpRequest();
xhr.open("POST","Login.aspx",true);
xhr.setHeaderRequest("Content-Type","Application/x-www-form-urlencoded");
xhr.onreadystatechange=function(){
   if(xhr.readyState==4){
      ifif(xhr.status==200){
          document.getElemetById("div1").innerHTML=xhr.responseText;
       }
   }
}
xhr.send("Uname="+name);

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马