0

開始ページにフォーム処理を実装すると、システムでエラーが表示されます。

Express のコード

var http = require('http'),
express = require('express'),
app = express();

app.use(express.bodyParser());


// A route for the home page - and the page with a form

app.post('/', function(req, res) {

// Code for Handling the form

});

形:

<form action="/" method="post"> . . . </form>

今、私はこのエラーを受け取ります:

取得することはできません /

どうすればこの問題を解決できますか? いくつかのアイデア?

完全なルートの更新 - Jade を使用

// Set the view engine
app.set('view engine', 'jade');
// Where to find the view files
app.set('views', './views');
// A route for the home page - will render a view
    app.post('/', function(req, res) { 
    res.render('index');     
});

そしてここにフォームコード:

<form action="/" method="post">
<label>Name</label>
<input type="text" name="name">
<label>Text</label>
<textarea name="text" rows="10"></textarea>
<input type="submit">
</form>
4

1 に答える 1

1

リクエストだけでなく、リクエスト処理する必要があります。次のようなものが必要です:GETPOST

app.get('/', function (req, res, next) {
    res.render('index');
});

app.post('/', function (req, res, next) {
    // Code for handle the form data
});
于 2013-10-23T12:29:55.607 に答える