CodesJava

Easy learning with example program codes

Backbone.JS emulateJSON()


The Backbone.JS emulateJSON() method is used to handle the requests encoded with application/JSON.

Syntax:

Backbone.emulateJSON = true  

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>  
</head>  
<body>  
<script type="text/javascript">  
Backbone.emulateJSON = true;  
Backbone.sync = function(method, model) {  
document.write(method + ": " + JSON.stringify(model));  
model.set('id', 100);     
};  
var Stud = new Backbone.Model({  
name:"Tom",  
city:"London"  
});  
Stud.save();  
Stud.save({age: 10});   
</script>  
</body>  
</html>

Output:

create:{"name":"Tom","city":"London"}update: {"name":"Tom","city":"London","id":100,"age":10}
Please follow and like us:


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