我是Backbone.js的新手,现在我需要使用ajax处理BackBone.js中的express路由器方法结果,我知道如何使用jquery完成此任务。但没有使用jQuery如何使用Backbone.I已经了解了骨干路由器,模型,视图和集合,但我仍然不清楚。如何使用ajax处理BackBone.js中的express路由器方法
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);
我处理这取决于请求我需要发送的page.In的头部和身体“结果”参数我送身体快递所有要求和标题,但我不知道如何得到Backbone.js.Below代码的结果是处理来自节点js.js的ajax响应。它是正确的。
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);
}
});
? –
@Maxi Baez不,我没有使用集合来下载html代码。在所有请求的服务器中,我将为常见的html模板提供服务。然后根据请求我将获取页面的正文和标题并将其发送给客户端。 – sachin