【发布时间】:2016-05-22 06:55:51
【问题描述】:
我有我的路由器的代码
var express = require('express');
var router = express.Router();
function sendSolve(test) {
// Some code for calculations
}
/* POST listing. */
router.post('/', function (req, res, next) {
sendSolve(req.body.data);
next();
}, function (req,res) {
res.json({"message": "ok"});
});
module.exports = router;
客户端代码:
$('.button').on('click', function () {
var $textArea = $('#textArea');
var newData={data: $textArea.val()};
$.post('/', newData, function (res) {
console.log(res);
$textArea.val('');
});
});
然后我首先$.post 一切正常,但在第二个帖子我收到错误
500 (Internal Server Error)k.cors.a.crossDomain.send @ jquery-2.1.4.min.js:4n.extend.ajax @ jquery-2.1.4.min.js:4n.(anonymous function) @ jquery-2.1.4.min.js:4(anonymous function) @ main.js:26n.event.dispatch @ jquery-2.1.4.min.js:3r.handle @ jquery-2.1.4.min.js:3
【问题讨论】:
-
您可能需要将前端代码添加到问题中,因为这是引发问题的地方。如果您使用 curl 或 postman,您会在多个帖子中收到错误吗?
标签: javascript node.js rest express