jquery Ajax 响应文本“处理请求时出错”

Car*_*Jr. 5 c# ajax jquery

我在 UAT 环境中收到此错误“处理请求时出错”。在我的本地,代码似乎运行良好。

这一行Utility.WriteLogEvent("TestService", strMessage); 直接写入数据库。无论这条线路是否失败,我仍然应该能够收到来自服务器的消息,因为它得到了正确的处理。

但是由于我没有收到服务器的任何响应,这意味着我的 webmethod 无法访问。

鉴于下面的代码有效,是否需要在 web.config 中设置任何内容才能使其正常工作?或者我可以开始检查可以给我一些线索的 IIS 的任何地方?

谢谢。

$('#lnkTest').click(function () {
    alert('Click event is firing!');
    $.ajax({
        type: "POST",
        url: "/_layouts/ServiceForm.aspx/TestService",
        data: "{}",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: function (response) {
            if (response.d && response.d.length > 0) {
                alert(response.d);
            }
        },
        error: function (xhr, err) {
            alert('responseText:' + xhr.responseText);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

这是我的 c# web 方法

[WebMethod]
public static string TestService()
{
    string strMessage = string.Empty;
    try
    {
        strMessage = "The service is running.";
        Utility.WriteLogEvent("TestService", strMessage);
    }
    catch (Exception ex)
    {
        strMessage = "TestService fail.";

    }
    return strMessage;
}
Run Code Online (Sandbox Code Playgroud)

Dum*_*ani 5

对于在使用参数调用 WebMethod 时可能遇到相同错误的其他人。

确保没有任何参数为空,因为这也会在没有适当原因的情况下引发相同的错误。提供解决方案以防止将空参数传递给客户端的方法。也许是一个if statement


Car*_*Jr. 0

我已经解决了这个问题。这是由于应用程序服务器中部署了 dll,并且被安装的防病毒软件阻止了。