When it comes to writing a JSON block, there are various methods one can use. Personally, I prefer the following approach:
$.post('/controller', { variable : variable }, function(data){
if(data.status == '304') {
// No changes over the previous
} else if(data.status == 'ok') {
// All is good, continue on and append whatever...
} else if(data.status == 500) {
// Server error, brace yourself - winter is coming!
}
}, "json");
I have experimented with changing the last condition to statements like else if data.status == null, 500, false, or simply as an else statement, but with no success. It appears that due to returning a 500 error and failing to retrieve any information at all, the code does not execute anything within the brackets. Is there a need for an exception to be implemented outside of it, or am I mistaken?
What steps should I take to make this function without relying on something similar to
$.ajax({
url : '/controller',
type : 'POST',
dataType : {
lookup : JSON.stringify(lookup)
},
data : lookup,
contentType : 'application/json; charset=utf-8',
success: function (data) {
// Stuff
},
error: function (xhr, ajaxOptions, thrownError) {
// Stuff
}
});
Appreciate your help!