reactjs - ReactJS Fetch 无法加载 json,输入意外结束
问题描述
我正在从 nginx 服务器加载一个 json 文件。使用 reactjs 公共数据加载工作正常。
但我只是将数据文件夹移动到使用 nginx 的不同服务器
fetch(cdnUrl + "/data/content.json", { mode: 'no-cors' })
.then(res => res.json())
.then(result => {
console.log('result is');
console.log(result);
}).catch(error => {
console.log(error);
});
我想我一定是错误地配置了 nginx。但我不知道到底是什么问题
配置
server {
listen 80;
listen [::]:80;
server_name cdn.server;
location / {
root /home/ec2-user/cdn;
index index.html;
log_not_found off;
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
}
我收到以下错误 错误 SyntaxError: Unexpected end of input
但在我将 json 移动到 nginx 之前它工作正常(同一台服务器运行良好)
响应头
Content-Encoding: gzip
Content-Type: application/json
Date: Fri, 09 Oct 2020 08:11:42 GMT
ETag: W/"5f79f20f-548"
Last-Modified: Sun, 04 Oct 2020 16:02:23 GMT
Server: nginx
Vary: Accept-Encoding
解决方案
推荐阅读
- c# - 给定类型 T,解析并使用泛型类型 Calc 的其他对象
处理 T - ruby - 以纯 Ruby 脚本的进度上传到 S3
- sql-server - 带有 sqlalchemy 的 mssql + pymssql 引擎不接受连接字符串中的属性
- azure-cosmosdb - Cosmos DB Sql Api - 查询 C# 转义的内部 json
- javascript - 如何在我的响应代码中获取 unicode U0022 值(“)而不获取此“\”
- angular - 注入服务更改时,HTML 未在角度测试中更新
- html - 水平线中间有单词时如何去除背景白色
- docker - 损坏的 DAG:(...)没有名为 docker 的模块
- php - Angular 5和PHP无法使用cryptoJS解密php中的加密变量
- java - 使用 LIMIT AND OFFSET 时,H2 嵌入式数据库不返回正确的结果