理解Form中get和post的两种方式

来源:互联网 发布:索尼l36h挂起网络 编辑:程序博客网 时间:2024/05/12 01:09

 1、使用POST方式:
客户端代码:
        // Create XMLHttpRequest object
        CreateXmlHttp();
       
        // Build the URL to connect to
        var url = "ValidateName.aspx";

        // Open a connection to the server
        xmlHttp.open("POST", url, true);

        // Setup a function for the server to run when it's done
        xmlHttp.onreadystatechange = callBack_CheckName;
       
        xmlHttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');

        // Send the request
        xmlHttp.send("name=" + escape(name) );

后台如何接收参数:
       Request.Form["name"]


2、使用Get方式:
客户端代码:
        // Create XMLHttpRequest object
        CreateXmlHttp();
       
        // Build the URL to connect to
        var url = "ValidateName.aspx?name=" + escape(name);

        // Open a connection to the server
        xmlHttp.open("GET", url, true);

        // Setup a function for the server to run when it's done
        xmlHttp.onreadystatechange = callBack_CheckName;

        // Send the request
        xmlHttp.send(null );

后台如何接收参数:
       Request.QueryString["name"]

 

Request.QueryString从地址栏中获取值,Request.Form从表单中获取值

post方法地址栏中无参数显示,,将整个form表单提交

 

 

使用post方法

 send.aspx

receive.aspx.cs

在页面上显示的地址http://localhost:5689/WebSite/receive.aspx

 

使用get方法

send.aspx

 

receives.aspx.cs

 

在地址栏中显示http://localhost:5689/WebSite/receives.aspx?txtname=kong&txtage=22

原创粉丝点击