使用 fetch API 发生意外的输入结束错误

using of fetch API the unexpected end of input error occurr

fetch('http://www.freegamesforyourwebsite.com/feeds/games/?
tag=platform&limit=100&format=json',
{
method:'GET',
mode:'no-cors',
dataType: 'json',
    headers: {
        'Accept': 'application/json'
    }  

}).then(response =>
response.json()).then(addImage).catch(e => requestError(e,'image'));

console.log

SyntaxError: Unexpected end of input
 at fetch.then.response ((index):159)
 at <anonymous>

我尝试在 cros 平台上使用 fetch json,为什么 Google 开发者工具中的请求 header 向我显示提供请求 header.And 预览部分可以show me the json response,但是response promise之后的promise无法读取数据,报错如console log above.and 我fetch的URL是开源的,可以供大家使用。

感谢任何帮助。

你说 mode:'no-cors',所以 fetch 不会尝试跨源读取数据(默认情况下是禁止的),也不会抛出错误(因为你告诉它你不想尝试跨源读取数据)。

改为mode: "cors"

确保您请求数据的服务器授予您使用 Access-Control-Allow-Origin header.

读取响应的权限

另见 this answer about the Same Origin Policy