How to load JSON with fetch?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
34 views
Want via Ajax request to JSON file groups, which is in the project. That is, locally. But the catch is triggered. Still can't understand why and how to fix it
error: Error: Request failed with status code 404 at createError (createError.js:16) at settle (settle.js:18) at XMLHttpRequest.handleLoad (xhr.js:77)

fetch( 'src/rest/groups.json', { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' } } ).then(response => { console.log('resp: ', response); return responce.json(); }).then(resp => { console.log('resp: ', resp); });


or the same but using axios

axios({ method: 'GET', url: 'http://localhost:3000/rest/groups.json' }).then(resp => { console.log(resp); }).catch(e => { console.error('error: ', e); });
by | 34 views

2 Answers

0 like 0 dislike
status code 404

Page not found. Check the url where requests are sending.
by
0 like 0 dislike
Just checked, if you specify the url file:///C:/git-repo/todos/rest/groups.json, 404 not emboss, but it turns out another error: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
by

Related questions

0 like 0 dislike
1 answer
asked Jun 10, 2019 by rsoinvi
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users