【发布时间】:2019-05-13 01:11:49
【问题描述】:
我正在尝试向 nodejs 服务器发送 post 请求,但我遇到了错误。
我的 .js 文件中有这段代码
var 数据 = { 名字:“ABC”, 姓氏:“ABC”}
var jax = $.post('/update', { data: data });
在 nodejs 服务器中,我有这个代码
app.post('/update', function(req, res){
console.log('body: ' + JSON.stringify(req.body));
var obj = req.body.data;
console.log("obj is " + JSON.stringify(obj));
// res.send(req.body);
})
;
每次我运行程序我都会收到这个错误提示 "$.post is not a function"
【问题讨论】:
-
基于错误,我假设您对 jQuery 的使用有疑问。您是否在客户端页面上加载 jQuery?试试 jQuery.post(....) 或者在你的头脑中添加 jQuery 库。
-
我在我的 HTML 中添加了 jQuery,我也尝试使用 jQuery.post 但它不起作用
-
你有没有加载其他库,你确定在jQuery加载后执行$.post吗?你在哪里执行 $.post?
-
您使用的是精简版 Jquery,因为 Ajax 不是精简版 jquery 的一部分。您需要使用 jquery 的缩小版或未压缩版。
-
我还添加了 bootstrap 和 mapbox 的库,我的 .post 是在所有文档加载后执行的。里面 $(document).function(){ // 代码 }
标签: jquery html node.js ajax post