I have created a C# WebService (ASMX) with the code snippet below:
if (!SomeValidation())
{
//context.Response.ContentType = "application/json";
//context.Response.ContentType = "text/plain";
context.Response.ContentType = "application/text";
context.Response.StatusCode = 400;
context.Response.Status = "400 Bad Request";
context.Response.StatusDescription = "Bad Request";
context.Response.Write("Error Message");
//context.Response.Write("{ ErrorMessage: "Error Message" }");
context.Response.End();
return;
}
This ASMX is called through AJAX, and its error handling function includes:
error: function (request, status, error) {
if (request.status === 400) {
ShowMessage("Warning", request.responseText);
console.log(request);
} else {
ShowMessage("Failure", "Error.");
console.error(request);
console.error(status);
console.error(error);
}
}
While running the code locally displays the correct message, when published, it fails to display the expected outcome and instead shows the Status Code message.
What could be causing this inconsistency?
Note: The commented sections in the code were attempted fixes that did not work as intended.