I have an application that fires an ajax jsonp request to a C# HttpHandler.
function RequestData() {
var parameters = 'value1=' + value + '&value2=' + value2;
$.ajax({
type: "GET",
url: 'https://localhost:44300/checkvalues?' + parameters,
dataType: "jsonp",
headers: { "cache-control": "no-cache" },
success: function (msg) {
alert('all good')
},
error: function (jqXHR, exception) {
alert(jqXHR.status);
}
});
And here is some of the server side code.
if (OK)
{
response.ContentEncoding = System.Text.Encoding.UTF8;
response.ContentType = "application/javascript";
response.Write(callback + "({ data: 'allOK' });");
}
else
{
//error
response.StatusCode = 500;
response.SuppressFormsAuthenticationRedirect = true;
response.StatusDescription = "error";
response.End();
}
When OK is true, there is no problem. The ajax success function is called as expected. But the minute that I set the response status code to e.g. 500 to trigger the error section of the ajax request, the server response is never received - nothing happens.
How can I modify my response code to enter the ajax error section?
I can trigger a parse-error by changing the response, but I want to do it with Http Status Codes.