0
我有以下的小型express.js應用程序和相應的.jade文件。服務器運行沒有錯誤,但是當我提交按鈕時,沒有任何反應。我期望app.post(...)被調用,但事實並非如此。在Express.js中傳遞來自jade的表單數據
有人能指出我的錯誤嗎?
var express = require('express');
var http = require('http');
var bodyParser = require ('body-parser');
var app = express();
var port = process.env.PORT || 9250;
var host = process.env.HOST || "127.0.0.1";
var server = http.createServer(app).listen(
\t \t port,
\t \t host,
\t \t function() {
\t \t \t console.log("Server listening to %s:%d within %s environment",
\t \t \t \t \t host, port, app.get('env'));
\t \t });
app.set('views', __dirname + '/views');
app.engine('.html', require('jade').__express);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/', function(req, res) {
\t res.sendFile(app.get('views') + '/index.html')
});
app.get('/test', function(req, res) {
\t res.render('home.jade');
});
app.post('/claim', function(req, res) {
\t console.log('called');
\t res.redirect('/');
});
doctype html
html(lang="en")
head
title Hello
body
h1 Welcome
p Description
form(action="/claim", method="post")
label Input something
br
input(type="text", name="address", size=50)
br
input(type="submit", value="Submit")
大的壓痕問題。謝謝!它現在工作正常! – nullpointr
不客氣。 :) – Mindsers