【发布时间】:2017-02-09 13:01:01
【问题描述】:
我正在尝试使用 vue.js 将数据发送到我的 node.js 服务器,但浏览器控制台一直显示 404:POST http://127.0.0.1:63342/myaction 404 (Not Found)
vue.js:
this.$http.post('http://127.0.0.1:63342/myaction', this.formData).then(response => {
console.log(response.body);
}
node.js:
var express = require('express');
var bodyParser = require('body-parser');
var exp = express();
exp.use(bodyParser.urlencoded({extended: true}));
exp.post('/myaction', function (req, res) {
res.send('saved: "' + req.body.name + '".');
});
exp.listen(63342, function () {
console.log('Server running at', this.address());
});
当我启动我的服务器时,它说它正在{ address: '::', family: 'IPv6', port: 63342 } 运行
POST 在没有 vue.js 的情况下工作,只需提交 HTML form,但现在 AJAX 不支持。我尝试了多个端口和文件夹,但无法找出错误。
【问题讨论】:
标签: javascript ajax node.js post vue.js