+ 2
Why is this not working
I am trying to get the use the fetch api but it's not displaying anything https://code.sololearn.com/wzCynwC5srOd/?ref=app https://code.sololearn.com/WC75gIKLsxvK/?ref=app
2 Answers
+ 2
Problems in your web code:
1. Line 12: document.querySelector will not work properly when used in head tag.
So move it inside body tag as the last child.
2. fetchData() function is used but it is actually not declared in your code.
3. Use a proper api url as search.php will not work in sololearn playground. e.g. https://jsonplaceholder.typicode.com/posts
4. Invalid object syntax in line 16, use ":" colon after headers key
5. Invalid method call at line 21, response.Json().
Use response.json() to fix it. Use lowercase "j"
+ 1
Maybe the result needs to be JSON formatted. This link covers XHR but you can focus on the part that covers returning JSON object instead đ
https://www.w3schools.com/js/js_json_php.asp