Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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
Asp.net jquery ajax调用错误方法而不是success的响应_Asp.net_Jquery - Fatal编程技术网

Asp.net jquery ajax调用错误方法而不是success的响应

Asp.net jquery ajax调用错误方法而不是success的响应,asp.net,jquery,Asp.net,Jquery,我正在调用jQueryAjax来访问一个页面,如下所示 <script type="text/javascript"> function Showgrid() { $.ajax({ type: "GET", url: "popup.aspx", contentType: "application/json; charset=utf-8", data: {loca

我正在调用jQueryAjax来访问一个页面,如下所示

  <script type="text/javascript">
    function Showgrid() {
        $.ajax({
            type: "GET",
            url: "popup.aspx",
            contentType: "application/json; charset=utf-8",
            data: {locale: 'en-US' },
            dataType: "json",
            success: function (data) {
             $("#target").html(data.d);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);

            }
                    });

    }
</script>
我得到的是响应,但不是成功方法,而是错误函数
请说明错误所在

更改为
POST
,即改为
键入:“POST”
。在页面中转到
Response.Write(请求[0])

您在.aspx页面上的输出不是json类型。在写入响应之前使用Json编码或更改数据类型:text

如上所述,将type更改为POST并将数据括在引号中。在服务器端,需要调用web方法。传递参数“locale”时不能使用page_load。请参阅下面修订的JSON函数和服务器代码(假设您使用的服务器端代码正确):

JSON:


请改用Asp.net页面方法。谷歌就是这样。
 protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "text/plain";
    Response.Write(Request.QueryString[0]);
    Response.Write(DateTime.Now.ToString());
    Response.End();
}
protected void Page_Load(object sender, EventArgs e)
    {

    }


[System.Web.Services.WebMethod]
    public static void ShowGrid(string locale)
    {
        HttpContext.Current.Response.ContentType = "text/plain";
        HttpContext.Current.Response.Write(HttpContext.Current.Request.QueryString[0]);
        HttpContext.Current.Response.Write(DateTime.Now.ToString());
        HttpContext.Current.Response.End();
    }
function Showgrid() {
    $.ajax({
        type: "POST",
        url: "popup.aspx/ShowGrid",
        contentType: "application/json; charset=utf-8",
        data: "{ 'locale': 'en-US' }",
        dataType: "text",
        success: function (data) {
            $("#target").html(data.d);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);

        }
    });

}