首页 > Web开发 > 详细

【转】Ajax中send方法参数的使用(get/post)

时间:2015-01-20 11:48:16      阅读:408      评论:0      收藏:0      [点我收藏+]

Ajax中send方法参数的使用

 

一般情况下,使用Ajax提交的参数多是些简单的字符串,可以直接使用GET方法将要提交的参数写到open方法的url参数中,此时send方法的参数为null。

 

例如 :

      var url = "login.jsp?user=XXX&pwd=XXX";

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

      xmlHttpRequset.send(null);

 

此外,也可以使用send方法传递参数。使用send方法传递参数使用的是POST方法,需要设定Content-Type头信息,模拟HTTP POST方法发送一个表单,这样服务器才会知道如何处理上传的内容。参数的提交格式和GET方法中url的写法一样。设置头信息前必须先调用open方法。

 

例如:

     xmlHttpRequest.open("POST","login.jsp",true);

     xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");

     xmlHttpRequest.send("user="+username+"&pwd="+password);

 

 需要注意的是根据提交方式的不同,两种提交方式分别调用后台的doGet方法和doPost方法。

【转】Ajax中send方法参数的使用(get/post)

原文:http://www.cnblogs.com/liuyuqing8/p/4235589.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!