Ajax call:
$.ajax(
{
url: "Service URL here",
method: "POST",
data: {params here},
contentType: "application/json",
processData: false,
success: function (response) {
//success code here
},
error: function (jqXhr, textStatus, errorThrown) {
errorHandler(jqXhr);
},
complete: function () {
//complete action
}
});
Common JavaScript function:
function errorHandler(jqXhr)
{
switch(jqXhr.status)
{
//here added
case 0:
toastr.error("Please check your internet connection");
//alert("Please check your internet connection");
break;
case 401:
toastr.error("Unauthorized access");
//alert("Unauthorized access");
break;
case 404:
toastr.error("Page not found");
//alert("Page not found");
break;
case 500:
toastr.error("Internal server error");
//alert("Internal server error");
break;
default:
toastr.error("Oops something went wrong, Try again latter.");
//alert("Oops something went wrong, Try again latter.");
break;
}
}
$.ajax(
{
url: "Service URL here",
method: "POST",
data: {params here},
contentType: "application/json",
processData: false,
success: function (response) {
//success code here
},
error: function (jqXhr, textStatus, errorThrown) {
errorHandler(jqXhr);
},
complete: function () {
//complete action
}
});
Common JavaScript function:
function errorHandler(jqXhr)
{
switch(jqXhr.status)
{
//here added
case 0:
toastr.error("Please check your internet connection");
//alert("Please check your internet connection");
break;
case 401:
toastr.error("Unauthorized access");
//alert("Unauthorized access");
break;
case 404:
toastr.error("Page not found");
//alert("Page not found");
break;
case 500:
toastr.error("Internal server error");
//alert("Internal server error");
break;
default:
toastr.error("Oops something went wrong, Try again latter.");
//alert("Oops something went wrong, Try again latter.");
break;
}
}