CodesJava

Easy learning with example program codes

Backbone.JS Sync()


The Backbone.JS Sync() model communicates with the server and also represents state of a model.

Syntax:

Model.Sync (method, model, options)

Parameters:
method: This parameter is used to specify the create, read, update and delete operations, also called as the CRUD operations.
model: This parameter is used to save the data on the model.
options: This parameter is used to fire SUCCESS or ERROR messages.

Example:

<!DOCTYPE html>  
<html>
<head>  
<title>Example</title>  
<script src="https://code.jquery.com/jquery-2.1.3.min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js" type="text/javascript"></script>  
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js" type="text/javascript"></script>  
<script type="text/javascript">  
var details = new Backbone.Model({  
subject: "Hello!",  
msg: "Welcome."   
});  
Backbone.sync = function(method, model) {  
document.write(method + ": " + model.get('subject')+ " " +model.get('msg'));  
};  
details.save();  
</script>  
</head>  
</html>

Output:

create: Hello! Welcome.
Please follow and like us:


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki