I'm making a JavaScript Ajax call to load the contents of a classic ASP page into a div.
When the target ASP page has an error I want to be able to detect it and display a message accordingly. The problem is that even if the ASP page has an error, the response code returned from the Ajax call is 200.
Currently I'm searching the response for the word "error" to determine if the target page errored but this has a distinct code smell about it and I'd like to cleanly check the response code. (I've left this bit out of the example)
This is what the target ASP page renders as:
My Ajax code on the calling page is as follows:
function GetCompanyDataPage(companyID) {
$.ajax({
type: 'GET',
url: 'workflow_companyData.asp?companyID=' + companyID.toString(),
dataType: 'html',
success: function (xml, textStatus, xhr) {
console.log(arguments);
console.log(xhr.status);
console.log(textStatus);
},
statusCode: {
200: function(xhr) {
if(window.console) console.log("**** Status code 200 *** " + xhr.responseText);
}
},
complete: function (xhr, textStatus) {
console.log(xhr.status);
}
});
The resulting console messages are:
200 success **** Status code 200 *** undefined 200
I'm struggling to find how to do this - maybe I'm googling for the wrong thing, maybe it's not possible. Please help.
UPDATE
I am thinking that this is simply not possible because the target ASP page that has the error is still rendering correctly, it's not presenting a browser error. Therefore the Ajax call is correctly seeing the call as successful. I think the only thing I can do is to search for an error in the response text as I'm currently doing.