Thursday, 14 June 2018

025 BackboneJS Backbone.emulateJSON

Backbone.emulateJSON
 

If your browser is legacy and can't handle requests encoded as application/json.Backbone.emulateJSON = true will serialized under a model parameter.

Syntax : Backbone.emulateJSON = true
 
Example



<!DOCTYPE html>
<head>
<title>Router Extend 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>
<script type="text/javascript">

Backbone.emulateHTTP = true;

Backbone.sync = function (method, model)
{
document.write(method + ": " + JSON.stringify(model) + "");
model.set('id', 1);
};

var student = new Backbone.Model
({
name: "john",
class: 4
});

student.save();
student.set({ name: "john2" });
student.save();
student.destroy();
</script>

Output :

create: {"name":"john","class":4}
update: {"name":"john2","class":4,"id":1}
delete: {"name":"john2","class":4,"id":1} 

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...