I'm new to Backbone.js now i need to handle the express router method result in BackBone.js using ajax i know how to do it with jquery.But without using jquery how to do it with Backbone.I have learned about Backbone router,model,view and collection but still i'm not clear.
app.js
var express=require('express');
var app=express();
app.use(express.bodyParser());
app.all('*',function(req,res){
res.writeHead(200, {'Content-Type': 'text/json'});
res.write(JSON.stringify(result));
res.end();
});
app.listen(8080);
I'm handling all request in express depending upon the request i need to send the header and body of the page.In that 'result' parameter i'm sending the body and header but i don't know how to get that result in Backbone.js.Below code is to handle the ajax response from node js.Is it correct.
client.js
var MyModel = Backbone.Model.extend();
var MyCollection = Backbone.Collection.extend({
url: '/index.html',
model: MyModel
});
var coll = new MyCollection();
coll.fetch({
error: function (collection, response) {
console.log('error', response);
},
success: function (collection, response) {
console.log('success', response);
}
});