在get方法中使用XmlHttpRequest在url参数中发送信息,如何在aspx页面中检索这些参数?

时间:2022-08-24 12:55:23

I want to retrieve those two parameters which are passed in url
// Read the text file with an XMLHttpRequest

我想检索在url中传递的那两个参数//使用XMLHttpRequest读取文本文件

    var xh;
    if (window.XMLHttpRequest) {
        xh = new XMLHttpRequest();
        alert("Object created");
    }
    alert(xh);

    xh.onreadystatechange = function() {

        if (xh.readyState == 4 && xh.status == 200) {
            alert(xh.responseText);
            document.getElementById("d1").innerHTML = xh.responseText;
        }
    }
    xh.open("GET", "Default.aspx?name=Henry&lname=Ford"", true);
    xh.send();

</script>

Now i want to retrieve those two parameters in aspx page.

现在我想在aspx页面中检索这两个参数。

Code in aspx page-

aspx页面中的代码 -

using System;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(DateTime.Now);
}
}

1 个解决方案

#1


0  

You need to get that using QueryString as GET this is get request , params are passed using QueryString. For this url , you have to use following for in page_load to retrive.

你需要使用QueryString作为GET这是get请求,使用QueryString传递params。对于此URL,您必须在page_load中使用以下内容来进行检索。

//Default.aspx?name=Henry&lname=Ford

protected void Page_Load(object sender, EventArgs e)
{
    string name,lname;
    if(Request.QueryString["name"]!=null)
        name = Request.QueryString["name"].ToString();
    if (Request.QueryString["lname"] != null)
        lname = Request.QueryString["lname"];
}

#1


0  

You need to get that using QueryString as GET this is get request , params are passed using QueryString. For this url , you have to use following for in page_load to retrive.

你需要使用QueryString作为GET这是get请求,使用QueryString传递params。对于此URL,您必须在page_load中使用以下内容来进行检索。

//Default.aspx?name=Henry&lname=Ford

protected void Page_Load(object sender, EventArgs e)
{
    string name,lname;
    if(Request.QueryString["name"]!=null)
        name = Request.QueryString["name"].ToString();
    if (Request.QueryString["lname"] != null)
        lname = Request.QueryString["lname"];
}