如何获取数据从jQuery ajax post与ExpressJS
How to get data from jQuery ajax post with ExpressJS
嗨,我有一个jquery post数据,我要发送:
$.ajax({
type: "POST",
url: app.config.backend_2 + '/notifications/usernames',
data: data,
contentType: 'application/javascript',
dataType: 'json',
success: function (result) {
console.log(result);
}
});
这是我的快递收信人:
exports.save_usernames_for_notifications = function (req, res, next) {
var start = function () {
console.log(req);
};
start();
};
我该怎么做才能从ajax获得数据,并将其记录在save_username_for_notifications
函数中?
在expressjs应用程序中需要一个body解析器中间件来解析JSON req对象
https://www.npmjs.com/package/body-parser 要配置它,您需要以下代码app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // this is used for parsing the JSON object from POST
然后在express应用程序中获取数据只需执行以下命令
console.log(req.body.data)
相关文章:
- 在FrontEndphp-ajax-jquery中验证reCaptcha-google
- AJAX jquery json将数组发送到php
- 如何使用Ajax/jQuery设置cookie
- PHP/Ajax/jquery/JON-在Ajax Post之后将echo文本中的一部分作为变量返回
- 如何使用Ajax JQuery.ech()获取JSON值
- 使用springform时,如何在ajax/jquery中获取复选框值
- JSP AJAX jQuery填充表问题
- Piping Value: Ajax + JQuery
- 使用javascript Without Ajax/Jquery在特定行中启用文本框
- 在AJAX jQuery加载()之后运行jQuery代码
- 具有动态更新的实时标题 (AJAX+jQuery)
- ajax/jQuery Youtube 播放列表推送
- AJAX jQuery Avatar Uploading
- 全局变量 - AJAX jQuery
- Ajax jquery mysqli update
- 获取剩余时间和上传文件速度 - ajax jquery/js
- 使用ajax/jquery绑定Json数据
- TypeError Obj.root是未定义的ajax jquery
- 当数据类型为XML时,如何将url参数传递给AJAX jquery
- 在ajax Jquery之后无法获取隐藏字段的值