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;
}
                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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With