Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery Ajax responsetext "There was an error processing the request"

Tags:

jquery

c#

ajax

I am getting this error "There was an error processing the request" in the UAT environment. In my local, the code seems to be working fine.

This line Utility.WriteLogEvent("TestService", strMessage); is writing directly to db. Either way if this line fails or not, I should still be able to recieve a message coming from the server since it is properly handled.

But since I don't receive any response from the server, that means my webmethod is not reachable.

Given that the code below works, is there anything that I need to set in the web.config to make this work? Or anywhere I can start inspecting on the IIS that could give me some clues?

Thanks.

$('#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);
        }
    });
});

Here is my c# web method

[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;
}
like image 904
Carls Jr. Avatar asked Jul 25 '14 04:07

Carls Jr.


1 Answers

For others who might come across the same error while calling a WebMethod with parameters.

Ensure that none of the arguments are empty as that also throws the same error without a proper reason. Provide a solution to prevent empty arguments from being passed to the Method on the client side. Perhaps an if statement.

like image 107
Dumisani Avatar answered Oct 25 '22 03:10

Dumisani