Why is this not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

25th Dec 2020, 1:20 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
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"
25th Dec 2020, 2:05 PM
Art1mis
+ 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
25th Dec 2020, 1:31 PM
Ipang