javascript - 纯 html 文件和 vanilla js 中的 CORS 错误
问题描述
我试图制作一个带有表单的 html 文件,以便为我的 react-native 应用程序用户发送通知。
当我尝试执行此代码时,我正在使用 expo 推送通知:
const sendNotification = async (token, titre, news) => {
const message = {
to: token,
sound: 'default',
title: titre,
body: news,
data: { data: 'goes here' },
};
var request = new Request('https://exp.host/--/api/v2/push/send');
const url = 'https://exp.host/--/api/v2/push/send';
await fetch(request, {
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-encoding': 'gzip, deflate',
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
});
};
我收到 CORS 错误。
我对此进行了一些研究,我发现了很多关于 node js web 应用程序的东西,但没有关于 html 文件中的纯 js 的东西。
有什么解决办法吗?
解决方案
推荐阅读
- flutter - 将 facebook_audience_network 更新为 0.9.0 时出错
- python - 按最后一列中的值过滤数组
- javascript - 防止 SwiperJS 滑过最后一张幻灯片
- python - Python 中的 Twitter 情绪分析,Pandas 中的词形还原
- php - 从服务器的 [NGINX] MySQL 数据库创建和重新创建本地 Android 数据库
- r - 为什么 vglm 中的变量顺序会对 Hosmer Lemeshow 测试产生影响?
- django - Django Channels 2.4 ... WebSocket 消息是否总是按顺序到达
- python - 如何使用 python 和 pandas 重命名子文件夹中的多个 .Json 文件
- swift - Swift 中的 FSCalendar 日期选择错误
- gradle - 关于“编译项目()”Gradle 任务的问题?