CodesJava

Easy learning with example program codes

Backbone.JS Fetch()

The Backbone.JS Fetch() model is used to delegate sync() method in the model in order to accept the data from the server.

Syntax:

Model.Fetch( options)

Parameters:
options: This parameter is used to specify the options like name, id, etc.

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">  
Backbone.sync = function(method, model) {  
document.write(method + ": " + JSON.stringify(model));  
};  
var Y = new Backbone.Model({  
Subject:"Introduction",  
MSG: "HELLO WORLD!"  
});  
Y.fetch();  
</script>  
</head>  
</html>

Output:

read: {"Subject":"Introduction","MSG":"HELLO WORLD!"}

Explanation:
The Fetch() model fetched the data from the server.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status