I have a model,having url property.
When i save the model using “Save” method, it is sending request to the server.
If the communication is success, the success() method is triggering and if communictaion is failed, “error” function is being triggered.
But, what if there is no communication problem but when the server sends a “failed message” due to some server validations or for other reasons ?
As , due to server side validations(or others),the model not saved in server.
So, it shouldnot be saved in backbone model also.
What should i do to tell the model not to save when the server sends “Error updating database” and tell it to save when i receive “Successfully updated”
I am sending the below response from server :
$this->response(
array(
'model'=>$model,
'status'=>$status,
'metamodel'=>array(),
'message'=>$msg (either success or fail)(my custom message)
)
);
in the client side,i am saving like this.
model.save(attr{
success:(model,res)->
// to do when communication success
error:(model,res)->
//to do when communication fails
})
So, how can i check based on the message or the status whether server succeeded or not ?
And,how can i tel model not to save or revert the changes when server says “no”(NOT INTERNAL SERVER ERROR, my custom error bcoz of validations or other reasons)
Also, how can i use Backbone.Sync method ( practical example related to my code,please)
and what does it do? (plz mention clearly whether comunication problem or custom error mesage or internal server error)
I can access “status” and “message” in the “success” method , but how can i use them to revert changes to model .
Thanks
Overwrite the
parse(response)method on the model and check for an error flag.http://documentcloud.github.com/backbone/#Model-parse