By using jquery ajax function, I can do something like:
$.ajax({
url: url,
type: \'GET\',
async: true,
dataType: \'json\',
data: data,
success:
Simplest thing to do would be to restructure like so:
function handleAjaxError function(xhr, status, error) {
//Handle failure here
}
$.ajax({
url: url,
type: 'GET',
async: true,
dataType: 'json',
data: data,
success: function(data) {
//Handle server response here
if (data.message == 'There is an error')
{
handleAjaxError();
return;
}
//... all is good....
},
error: handleAjaxError
});