need help parsing a json array into an html table

MarioMasta64

hi. i make batch stuff and portable shiz
OP
Member
Joined
Dec 21, 2016
Messages
2,297
Trophies
0
Age
26
Website
github.com
XP
2,096
Country
United States
heres my code:
Code:
<html>
<head>
<script type="text/javascript" src="/res/js/jquery.min.js"> </script>
<script>
$.getJSON('/data.json',
function (data) {
    var tr;
    for (var i = 0; i < data.length; i++) {
        tr = $('<tr/>');
        tr.append("<td>" + data[i].name + "</td>");
        tr.append("<td>" + data[i].file + "</td>");
        tr.append("<td>" + data[i].description + "</td>");
        $('table').append(tr);
    }
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
    <table id="user_submissions" border="2">
      <thead>
        <th>Name</th>
        <th>URL</th>
        <th>Description</th>
        </thead>
    <tbody>

    </tbody>
    </table>
</div>
</div>
</body>
</html>

code now works :D
 
Last edited by MarioMasta64,

RHOPKINS13

Geek
Member
Joined
Jan 31, 2009
Messages
1,354
Trophies
2
XP
2,621
Country
United States
Do you get any javascript console errors in Chrome or Firefox?

I haven't really toyed with your code much, but just at first glance, shouldn't user_submissions be #user_submissions on this line?

$('user_submissions').append(tr);
 
  • Like
Reactions: MarioMasta64

MarioMasta64

hi. i make batch stuff and portable shiz
OP
Member
Joined
Dec 21, 2016
Messages
2,297
Trophies
0
Age
26
Website
github.com
XP
2,096
Country
United States
Do you get any javascript console errors in Chrome or Firefox?

I haven't really toyed with your code much, but just at first glance, shouldn't user_submissions be #user_submissions on this line?

$('user_submissions').append(tr);
tried it, still nothing.

--------------------- MERGED ---------------------------

Do you get any javascript console errors in Chrome or Firefox?

I haven't really toyed with your code much, but just at first glance, shouldn't user_submissions be #user_submissions on this line?

$('user_submissions').append(tr);
upload_2017-9-3_22-50-0.png
heres the error btw

--------------------- MERGED ---------------------------

i also added a ) after the url and same error.
 

MarioMasta64

hi. i make batch stuff and portable shiz
OP
Member
Joined
Dec 21, 2016
Messages
2,297
Trophies
0
Age
26
Website
github.com
XP
2,096
Country
United States
Have you tried passing that URL as a string? Because you are attempting to pass it as JavaScript code, which it is not.
o-o that may be it gonna try now

--------------------- MERGED ---------------------------

different error now (pretty sure this is due to perms or how its linked?)
upload_2017-9-3_23-11-34.png


--------------------- MERGED ---------------------------

changed it from a url to just data.json
no error's but nothing is added. but hey its a step in a direction :D

--------------------- MERGED ---------------------------

fixed it :DDDDDDDDDDDD changed user_submmissions to table and now it works. thanks everyone for helping out.

--------------------- MERGED ---------------------------

http://old-school-gamer.tk/view_submit.html :D now works thanks to you guys :D turns out it was just a simple error lol
 

Frederica Bernkastel

Well-Known Member
Member
GBAtemp Patron
Joined
Jan 31, 2008
Messages
3,169
Trophies
2
Age
28
Location
Hinamizawa
XP
989
Country
Japan
Happy to hear you got this working!

This isn't going to help solve your problem, but it will help you write cleaner and more maintainable browser JavaScript.
My advice is to get rid of jQuery to solve this particular task and to look into using Fetch, a newer browser API (will not work in older browsers, though it can be polyfilled with polyfill.io).

Something like this should work: http://jsbin.com/hepozekeki/edit?html,console,output
Hope this helps!
 
  • Like
Reactions: MarioMasta64

MarioMasta64

hi. i make batch stuff and portable shiz
OP
Member
Joined
Dec 21, 2016
Messages
2,297
Trophies
0
Age
26
Website
github.com
XP
2,096
Country
United States
Happy to hear you got this working!

This isn't going to help solve your problem, but it will help you write cleaner and more maintainable browser JavaScript.
My advice is to get rid of jQuery to solve this particular task and to look into using Fetch, a newer browser API (will not work in older browsers, though it can be polyfilled with polyfill.io).

Something like this should work: http://jsbin.com/hepozekeki/edit?html,console,output
Hope this helps!
its something to be commonly accessed (also i sometimes submit stuff from my flipphone lol) so yea, ill consider, but highly unlikely.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: But I bet that would be more for a flashcart than a consumer repro board.