Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从jQuery Get()方法调用的asp.net页返回值_C#_Jquery_Asp.net_Ajax - Fatal编程技术网

C# 如何从jQuery Get()方法调用的asp.net页返回值

C# 如何从jQuery Get()方法调用的asp.net页返回值,c#,jquery,asp.net,ajax,C#,Jquery,Asp.net,Ajax,如何从使用jQuery Get方法调用的asp.net页面返回一些值?下面给出了get方法,我希望警报应该显示返回的值 get调用result.aspx页面,该页面返回一个字符串以及我希望在警报中显示的字符串 $.get("result.aspx", { name: "Donald Duck", city: "India" }, function (result, status, xhr) { alert(result);

如何从使用jQuery Get方法调用的asp.net页面返回一些值?下面给出了get方法,我希望警报应该显示返回的值

get调用result.aspx页面,该页面返回一个字符串以及我希望在警报中显示的字符串

$.get("result.aspx",
    {
        name: "Donald Duck",
        city: "India"
    },
    function (result, status, xhr) {
        alert(result);
    }
);
result.aspx代码为:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        LoadReturn();
    }
}
void LoadReturn()
{
    string name = Request.QueryString["name"];
    string city = Request.QueryString["city"];
    string returnValue="Hello Mr."+ name + " who lives in " + city;

    //How to return value of returnValue to the jquery get() function. 

}
如何将returnValue的值返回到jquery get函数

更新 我试着回答。它能够将数据返回给jquery get方法

Response.Write(returnValue);
唯一的问题是它还向我发送result.aspx页面的完整HTML。这是我不想要的。
如何防止不必要的HTML到达jquery get方法?

我通过将Response.End放在末尾解决了这个问题。希望它也能帮助别人

void LoadReturn()
{
    string name = Request.QueryString["name"];
    string city = Request.QueryString["city"];
    string returnValue="Hello Mr."+ name + " who lives in " + city;

    Response.Write(returnValue);
    Response.End();
}

使用WebMethod或单独的.svc webservice文件。aspx页面设计用于从完整页面加载到整个HTML页面,而不是从HTML或JSON片段到ajax调用。本教程给出了一个使用WebMethod的简单示例。我知道.ajax方法,但如何在asp.net中使用.get返回?您是否尝试过响应。在响应之后结束。编写?如果您不只是想快速解决问题,ADysons的回答可能是正确的方法。@gb2d我还没有尝试过回答。End;。我现在就这么做了,多余的不必要的HTML页面不见了。问题解决了。谢谢,这对我也有帮助!