zoukankan      html  css  js  c++  java
  • 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.setRequestHeder("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");

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

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

  • 相关阅读:
    openlayers方法总结
    AJAX 数据库实例
    AJAX 请求服务器
    得到XMLHttpRequest对象
    AJAX 简介
    AJAX 服务器端的脚本
    HTTP GET 最多发送100个字符
    AJAX XMLHttpRequest 对象
    Dictionary、ArrayList、Hashtable和数组 Array 的区别
    AJAX 请求实例
  • 原文地址:https://www.cnblogs.com/blogofwu/p/3905189.html
Copyright © 2011-2022 走看看