save
can.Model.prototype.save
Save a model back to the server.
model.save([success[, error]])
Parameters
-
success
{function()}
OptionalA callback to call on successful save. The callback recieves the can.Model after saving.
-
error
{function()}
OptionalA callback to call when an error occurs. The callback receives the XmlHttpRequest object.
Returns
{can.Deferred}
A Deferred that resolves to the Model after it has been saved.
model.save([success(model)],[error(xhr)])
creates or updates the model instance using create or update depending if the instance has an id or not.Using
save
to create an instance.If
save
is called on an instance that does not have an id property, it calls create with the instance's properties. It also triggers a "created" event on the instance and the model.Using
save
to update an instance.If save is called on an instance that has an id property, it calls create with the instance's properties. When the save is complete, it triggers an "updated" event on the instance and the instance's model.
Instances with an id are typically retrieved with findAll or findOne.