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
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}
update: {"name":"john2","class":4,"id":1}
delete: {"name":"john2","class":4,"id":1}
No comments:
Post a Comment