Reputation: 4810
If i do
var model = new Model({ id : 'someNewId'});
model.fecth();
I then get a model filed with default value as the model wiht an idea of 'someNewId' does not exist on server.
What would be the best way to ensure that a model does exist on the server?
Upvotes: 3
Views: 1276
Reputation: 35920
It really depends on your server configuration. Typically a RESTful service would return a HTTP error code 404 to indicate that the resource was not found.
model.fetch({
success: function(model, response, options) {
//model exists and is now populated
},
error: function(model, xhr, options) {
if(xhr.status === 404) {
//model was not found
}
else {
//some other error
}
}
}
Upvotes: 6