You should return a promise on the values you need by using .then
, one of the cool things about promises is that they chain.
function getSomeData()
{
return $.ajax({
/*
...set my AJAX config options...
*/,
error: function(xhr, status, errorText)
{
// handle the error
}).then(function(data){
if (isLoginFormHTML(data)) {
showModalLoginDialog(data);
throw new Error("Unauthorized");..
}
return data;
}
});
}
Which would allow you to do:
getSomeData().done(function(jsonData){
//yay data
}).fail(function(){
//no data
});