Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.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/2/ajax/6.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# 显示来自ajax错误服务器的异常消息_C#_Ajax_Jquery - Fatal编程技术网

C# 显示来自ajax错误服务器的异常消息

C# 显示来自ajax错误服务器的异常消息,c#,ajax,jquery,C#,Ajax,Jquery,我使用以下代码在客户端上显示来自服务器的异常消息: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static void test(String text) { try { throw new Exception("Hello"); }

我使用以下代码在客户端上显示来自服务器的异常消息:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static void test(String text)
    {
               try
               {
                    throw new Exception("Hello");
               }

               catch (Exception ex)
               {
                HttpContext.Current.Response.Write(ex.Message);
                throw new Exception(ex.Message, ex.InnerException);
               }

    }
客户端:

    $.ajax({
        url: 'DownloadFile.aspx/test',
        type: 'POST',
        contentType: 'application/json; charset=utf-8',
        // Pass the value as JSON string                 
        // You might need to include json2.js for the JSON.stringify
        //method: 'http://www.json.org/json2.js',
        async: false,
        dataType: "json",
        data: '{ "text": "' + text'"}',
        success: function(Result) {

        },

        error: function(xhr, textStatus, errorThrown) {
            var err = eval("(" + xhr.responseText + ")");
            alert(err.Message);
        }
    });
当我使用localhost时,我在警报弹出窗口中得到“Hello”。 当我在远程服务器上使用相同的代码时,会出现一般的系统错误

如何让异常消息文本显示给用户

您需要在web.config中设置

你可以读更多


通常,您的mode=“RemoteOnly”只显示本地主机的详细异常消息。

您所说的“常规系统错误”是什么意思?正在调用jQuery错误处理程序吗?@Heather-是的,正在调用jQuery错误处理程序,但我收到了responseText消息:“处理请求时出错”