2 回答

TA貢獻1772條經驗 獲得超8個贊
https://docs.meteor.com/api/methods.html
Meteor.call("yourMethodName", (err, result) => {
// Put your code to update HTML with result
});
如果您想使用 Meteor.call,將您的 html 放在公用文件夾中也可能是個壞主意。

TA貢獻1796條經驗 獲得超4個贊
我已經解決了這個問題并解決了它。在 server/main.js 我添加這段代碼:
router.post('/method/example', (req, res, next) => {
let data = '';
req.on("data", chunk => {
data += chunk;
});
req.on('end', () => {
const result = dataHandler(data);
res.write(`${result}`);
res.end();
});
}
在 /public/example.js 中,我剛剛使用與 server/mains.js 中新行中相同的 URL 執行了一個 xhr post 請求。它是這樣的:
const xhr = new XMLHttpRequest();
xhr.open('post', '/method/example');
xhr.send(data);
xhr.addEventListener("load", () => {
const reqResult = xhr.responseText;
}
添加回答
舉報