0
我寫了一個使用骨幹的代碼片段,將POST的數據寫入到urlRoute。訪問骨幹model.save()POST負載在node-express後端
(function(){
"use strict"
window.Course = Backbone.Model.extend({
defaults:{
title:''
},
urlRoot:"courses/"
});
var courses = new Course({title:"Sending a Post request to the node-express backend,but how to access this in the backend"});
courses.save();
})();
我用node.js的 - 在後臺明確的框架,我想知道如何檢索使用app.post(「/課程」,函數(REQ,RES title屬性的值){})方法。 這是node.js後端,控件來到app.post方法,但只想要如何訪問發佈數據中的模型值。
var express = require('express')
, routes = require('./routes')
, user = require('./routes/user')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
app.post('/courses',function(req,res) {
console.log('Request successfully recieved');
console.log("how do i get the posted data here !!");
});
app.get('/', routes.index);
app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
它看起來不完整的,究竟你存儲在服務器端的機型?如果您只想在客戶端上列出它們,只需在其上創建一個'Backbone.Collection'和'.add()'模型,然後在客戶端進行查詢,然後在服務器上執行相同的操作,並繼續同步集合和模型,所以它可以在所有客戶端相同 – Gntem