【发布时间】:2020-11-03 05:50:50
【问题描述】:
我使用 node.js,Firebase 函数。 我尝试实现一个非常简单的函数(在函数/index.js 中),它使用 POST 方法从第三方网站获取响应:
exports.haveData = functions.https.onCall((data, context) => {
var $ = require('jquery');
$.ajax(
{
type: 'post',
url: 'http://example.com/info.html',
data: {
"id": data.id
},
success: function (response) {
console.log("Success !!");
},
error: function () {
console.log("Error !!");
}
}
);
return "Function ended";
});
但我有错误代码:
Unhandled error TypeError: $.ajax is not a function
at /workspace/index.js:35:7
at func (/workspace/node_modules/firebase-functions/lib/providers/https.js:273:32)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
我不知道可能是什么问题... :(
【问题讨论】:
-
有很多比 jquery 更好的库可以用来在 nodejs 中发出 HTTP 请求。
标签: javascript jquery node.js google-cloud-functions