Reputation: 1639
We're using LoopBack (by StrongLoop) for our REST framework. What is the best practice for determining success or failure?
A successful result simply returns the the data (in JSON). An unsuccessful result returns readyState, responseText, status and statusText. It would be really nice if the successful result also returned a status so we have a consistent method of checking for success/failure. However, we don't want to mix status codes in with our data either.
function write(authkey, type, url, data, callback) {
$.ajax({
type: type,
url: url,
contentType: "application/json; charset=utf-8",
data: data,
error: function (data) {
callback(data);
},
success: function (data) {
callback(data);
}
});
}
Upvotes: 0
Views: 144
Reputation: 2781
You should check the HTTP status code instead of depending on the results of the callback (ie. HTTP 200 = OK, 401 = Not Found, etc)
Upvotes: 1