【发布时间】:2017-07-13 04:54:54
【问题描述】:
为什么我的 HTTP.call() 函数没有按设计工作。
当我在浏览器控制台中运行以下代码时:
var postData = {
data: {
"username": "SirBT",
"productName": "Choma",
"phoneNumber": "+254700087633",
"currencyCode": "KES",
"amount": "666"
}
}
HTTP.call('POST', ''http://2117c3a8.ngrok.io/AConnect/c2b.php',
{ headers: { apiKey: 'AC6ea8e1541e7ee0c40915e' }},
postData,
function(error, result) {
if (error) {
console.log(error);
}
if (result) {
console.log(result);
}
}
);
我收到此错误消息:
Uncaught Error: Can't make a blocking HTTP call from the client; callback required.(…)
经过一番研究,我发现我应该从服务器运行它,我现在这样做了,但是我在终端中收到了这些错误消息:
W20170712-17:31:47.726(3)? (STDERR) /home/sirbt/escrow/.meteor/local/build/programs/server/packages/http.js:187
W20170712-17:31:47.728(3)? (STDERR) callback(error, response); // 74
W20170712-17:31:47.732(3)? (STDERR) ^
W20170712-17:31:47.733(3)? (STDERR)
W20170712-17:31:47.735(3)? (STDERR) TypeError: callback is not a function
W20170712-17:31:47.736(3)? (STDERR) at packages/http/httpcall_server.js:74:7
W20170712-17:31:47.737(3)? (STDERR) at packages/underscore.js:784:19
W20170712-17:31:47.738(3)? (STDERR) at Request._callback (packages/http/httpcall_server.js:116:5)
W20170712-17:31:47.740(3)? (STDERR) at Request.self.callback (/home/sirbt/.meteor/packages/http/.1.2.12.1w7h08f++os+web.browser+web.cordova/npm/node_modules/request/request.js:200:22)
W20170712-17:31:47.741(3)? (STDERR) at emitTwo (events.js:87:13)
W20170712-17:31:47.742(3)? (STDERR) at Request.emit (events.js:172:7)
W20170712-17:31:47.743(3)? (STDERR) at Request.<anonymous> (/home/sirbt/.meteor/packages/http/.1.2.12.1w7h08f++os+web.browser+web.cordova/npm/node_modules/request/request.js:1067:10)
W20170712-17:31:47.745(3)? (STDERR) at emitOne (events.js:82:20)
W20170712-17:31:47.746(3)? (STDERR) at Request.emit (events.js:169:7)
W20170712-17:31:47.747(3)? (STDERR) at IncomingMessage.<anonymous> (/home/sirbt/.meteor/packages/http/.1.2.12.1w7h08f++os+web.browser+web.cordova/npm/node_modules/request/request.js:988:12)
=> Exited with code: 1
期待您的帮助
【问题讨论】:
-
答案反映在错误信息中。你应该使用“回调”
标签: post meteor callback xmlhttprequest