reactjs - 如何从 expressjs 发送数据以响应客户端?
问题描述
我有一个payments.js
页面使用自定义表单来制作带有条纹的付款,看起来像这样
async handleSubmit() {
const { firstName, lastName, email, cardNo, expiryDate, cvv, nameOnCard } = this.state
const { price } = this.props.location.state.item
this.setState({
loading: true
});
await axios.post("/charge", {
firstName,
lastName,
email,
cardNo,
expiryDate,
cvv,
nameOnCard,
price
}).then((res) => this.setState({ iframeLink: res.data.next_action.redirect_to_url.url, loading: false }))
.catch((error) => console.log('ERR', error))
// I want this to wait for changes
await axios.post("/api/stripe/webhooks").then((res) => console.log(res)).catch((err) => console.log(err))
}
我正在打开在第一篇文章中收到的 url iframe
,一旦 3d 安全完成,我想用这条线获得条纹钩子,在第一次发布后调用一次,然后一旦收到另一个钩子就不会更新
await axios.post("/api/stripe/webhooks").then((res) => console.log(res)).catch((err) => console.log(err))
我的问题是此操作中从未收到数据
在服务器中,post 函数看起来像这样
// Stripe Webhooks
app.post("/api/stripe/webhooks", async function (req, res) {
try {
const query = req.body;
res.sendStatus(200);
console.log(query)
res.end(JSON.stringify(query))
} catch (err) {
console.log("/webhooks route error: ", err);
}
});
知道如何在收到数据时捕获数据吗?
解决方案
推荐阅读
- android - 模拟器中的 React Native run-android 错误“无法获取 BatchedBridge,请确保您的捆绑包已正确打包”
- django - 如何在相关模型之间添加 CheckConstraint
- android - 当您单击通知中的按钮时,问题是打开生物识别数据或密码输入模式
- c# - 使用 C# 行从数据库中检索 XML 列
- google-chrome - 有没有办法在初始化浏览器时删除 chromedriver 添加的所有默认浏览器功能?
- python-3.x - flask-sqlalchemy 中有没有办法使可继承的属性成为外键?
- java - ArrayList 不满足泛型可序列化列表类型
- javascript - 用 props 设置图片 src
- android - 如何禁止用户关闭触摸外部的警报对话框?
- django - Django - 添加没有默认 ModelAdmin 权限的模型(添加、更改、删除、查看)