SyntaxError:fetch中.json()之后输入的意外结束

时间:2016-12-18 21:28:22

标签: javascript asp.net json fetch

我正在使用fetch()从我的服务器中获取一些数据。 我以前做了很多次完全相同的事情但是现在我的浏览器给了我以下错误:Uncaught(在promise中)SyntaxError:意外的输入结束。 这发生在:

之后
getCategories()
.then((j)=> {    
    return j.json();
})

在响应j.json()时抛出错误,getCategories函数为:

export function getCategories() {
    var req = new window.Request(apiUrl + "/GetAllCategories",{
        method: "GET",
        mode: 'no-cors',
        dataType: 'json',
        headers: {
            'Accept': 'application/json'
        }   
    });
    return fetch(req);    
}

来自服务器的响应:[{"CategoryId":6,"Name":"Eten"}]

带标题的

Request URL:http://localhost:60249/api/app/GetAllCategories
Request Method:GET
Status Code:200 OK
Remote Address:[::1]:60249
Response Headers
view source
Cache-Control:no-cache
Content-Length:32
Content-Type:application/json; charset=utf-8
Date:Sun, 18 Dec 2016 21:20:01 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/10.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?    YzpcdXNlcnNcaWRzIHZhbiBkZXIgemVlXGRvY3VtZW50c1x2aXN1YWwgc3R1ZGlvIDIwMTdcUHJvamVjdHNcdWl0Z2F2ZSBzZXJ2ZXJcV2ViQXBwbGljYXRpb24xXGFwaVxhcHBcR2V0QWxsQ2F0ZWdvcmllcw==?=
Request Headers
view source
accept:application/json
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:60249
Referer:http://localhost:3000/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36`

0 个答案:

没有答案