CodesJava

Easy learning with example program codes

Backbone.JS emulateHTTP()

The Backbone.JS emulateHTTP() method is turned ON when the web server does not support REST or HTTP approach. It fakes PUT, PATCH and DELETE requests with an HTTP POST, if this method is set to true.

Syntax:

Backbone.emulateHTTP = 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.emulateHTTP = 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:
error









Copyright © 2019 CodesJava DMCA.com Protection Status