Backbone.emulateHTTP
If you server does not support REST/HTTP , your server is legacy , then you must use Backbone.emulateHTTP = true
Example
Output :
create: {"name":"john","class":4}
update: {"name":"john2","class":4,"id":1}
delete: {"name":"john2","class":4,"id":1}
If you server does not support REST/HTTP , your server is legacy , then you must use Backbone.emulateHTTP = 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