I am writing Javascript to know the different sites(dev, staging and prod) are UP or not. below is my code.
function URLStatusCheck(url)
{
try {
$.ajax(url,
{
contentType: "application/json; charset=utf-8",
dataType: 'jsonp',
crossDomain: true,
statusCode: {
404: function (xhr) {
alert("error 404");
},
200: function (xhr) {
alert("Site is UP");
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert("error");
}
}
}).fail(function (jqXHR, textStatus, errorThrown) {
alert("Fail");
});
} catch (err) { alert(url); }
}
I have problem with invalid URLs, below error are showing in the browser command for the invalid URLs.
Failed to load resource: the server responded with a status of 404 (Not Found)
Failed to load resource: net::ERR_NAME_NOT_RESOLVED
and those errors I am not able to catch them in any where (try/catch, error or 404). Could some one help me where(method or level) I can handled those errors.
Thanks, KPK