Guest Posted October 29, 2020 Share Posted October 29, 2020 <script> function getThem(id, url, a) { var request = new XMLHttpRequest(); request.open("GET", url); request.responseType = "json"; request.send(); request.onload = function() { var jsonObj = request.result; var tbody = document.querySelector(id); var tr = document.createElement("tr"); arra = [ jsonObj.result[a].Steam_ID, jsonObj.result[a].ShowAsOffline ]; for (p = 0; p < arra.length; p++) { var td = document.createElement("td"); td.textContent = arra[p]; tr.appendChild(td); } tbody.appendChild(tr); }; } const tableApis = [ "my url" ]; for (let table = 0; table < 4; ++table) { for (let a = 0; a < 6; a++) { getThem("#table" + (table + 1), tableApis[table], a); } } </script> <table class="table"> <thead> <tr> <th scope="col">1/th> <th scope="col">2</th> </tr> </thead> <tbody id="table1"> </tbody> </table> </div> </div> </div> { "result": [ { "User": { "UserName": "test", "InSped": true, "FormatName": "test" }, "isTeamMember": false, "ShowAsOffline": false, "State": 0, "Steam_ID": 123, "Spotify_TitleURI": "" } ], "error": false, "msg": null, "version": 202010231 } I get this errors https://prnt.sc/v9e7pd https://prnt.sc/v9e83o Quote Link to comment https://forums.phpfreaks.com/topic/311656-json-http-request/ Share on other sites More sharing options...
gw1500se Posted October 29, 2020 Share Posted October 29, 2020 What you posted is not any error known to PHP. If you are posting a link to errors, don't. Post the errors themselves and indicate to what line numbers the errors refer. Quote Link to comment https://forums.phpfreaks.com/topic/311656-json-http-request/#findComment-1582133 Share on other sites More sharing options...
kicken Posted October 29, 2020 Share Posted October 29, 2020 var jsonObj = request.result; This sets jsonObj to undefined because XMLHttpRequest doesn't have a result property. You need to read and parse the responseText property. XMLHttpRequest is an older standard. You might also want to look at the more modern fetch() API instead. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311656-json-http-request/#findComment-1582139 Share on other sites More sharing options...
Guest Posted November 2, 2020 Share Posted November 2, 2020 (edited) On 10/29/2020 at 5:54 PM, kicken said: var jsonObj = request.result; This sets jsonObj to undefined because XMLHttpRequest doesn't have a result property. You need to read and parse the responseText property. XMLHttpRequest is an older standard. You might also want to look at the more modern fetch() API instead. I changed it to var jsonObj = request.response; but the table still doesn't show anything Edited November 2, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311656-json-http-request/#findComment-1582188 Share on other sites More sharing options...
Guest Posted November 2, 2020 Share Posted November 2, 2020 @kicken Quote Link to comment https://forums.phpfreaks.com/topic/311656-json-http-request/#findComment-1582195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.