zoukankan      html  css  js  c++  java
  • 为什么Ajax XMLHttpRequest POST方法传递参数失败了

    XMLHttpRequest 可以Get,也可以Post向服务器传递参数

    var xhr = new XMLHttpRequest();
    $(document).ready(function(){
    $("button").click(function(){

    var paras = 'firstname=zhang&lastname=san';
    //Get 方式,直接将参数放到URL链接中
    xhr.open("get","God.asp?firstname=zhang&lastname=san&toGod=Gold");
    xhr.send(null);


    //Post 方式,参数放在单独的请求中
    xhr.open("post","God.asp");
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
    xhr.send('firstname=zhang&lastname=san');

    如果Post方式,需要指定内容的格式:

    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");

    后台使用ASP

    <%

    dim fn
    fn = Request.querystring("firstname")
    if (fn = "") then
      fn = Request.Form("firstname")
    end if

    dim ln
    ln = Request.querystring("lastname")
    if (ln = "") then
      fn = Request.Form("lastname")
    end if

    %>

    对于Get方式传参, 使用Request.querystring();

    而是用Post方式传参,使用Request.Form()

    当然,POST传递参数,有四种方式,

    form-data、x-www-form-urlencoded、raw、binary

    有兴趣的同学,可以再研究一下。

  • 相关阅读:
    如何用Django建立一个后台CRM系统02
    如何用Django建立一个后台CRM系统01
    多线程的UDP聊天器
    文件被导入时,能够直接执行的代码不需要被执行
    主动抛出异常
    python异常
    初始化动作只执行一次
    单例设计模式代码实现
    类的继承
    多态的案例演示
  • 原文地址:https://www.cnblogs.com/montai/p/13245949.html
Copyright © 2011-2022 走看看