私は Backbone.js を初めて使用するので、Express ルーター メソッドを処理する必要があります。その結果、ajax を使用して BackBone.js が生成されます。jquery でそれを行う方法を知っています。 、モデル、ビュー、およびコレクションですが、まだ明確ではありません。
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);
ページのヘッダーと本文を送信する必要があるリクエストに応じて、すべてのリクエストを明示的に処理しています。その「結果」パラメーターで、本文とヘッダーを送信していますが、その結果を取得する方法がわかりませんBackbone.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);
}
});