Display JSON Data in HTML Table Using JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ม.ค. 2025

ความคิดเห็น • 144

  • @DigitalFox-tutorials
    @DigitalFox-tutorials  2 ปีที่แล้ว +8

    Hi guys, i didn't mention in the video, that the script needs a local server like wamp, or xampp to run.
    If you more a reader, you can read the article and download the source code from my website:
    digitalfox-tutorials.com/tutorial.php?title=Fetch-data-stored-in-a-json-file-with-JavaScript

    • @unclegazza5783
      @unclegazza5783 2 ปีที่แล้ว

      Can you show us how use Ajax to add the product into the shopping cart🤔

    • @aholiab4321
      @aholiab4321 2 ปีที่แล้ว

      But the link is not working, I've been trying to download since yesterday

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      @@unclegazza5783 Yes soon

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      ​@@aholiab4321 Hey, it works i just tested it out, this is a link to the article on my website, you will find the download button at the end of the article.

    • @aholiab4321
      @aholiab4321 2 ปีที่แล้ว

      @@DigitalFox-tutorials I got my firsnz to try it from here also, did you restrict Nigerian IP address to your website 😭😭.

  • @christopherpink842
    @christopherpink842 2 ปีที่แล้ว +16

    THANKS nicely explained straight to the point and easy to understand in less than 5 minutes compared to other 1 hour complicated youtube videos

  • @Bowlingkegel97
    @Bowlingkegel97 ปีที่แล้ว +8

    This guy is the MAN! He is helpful, and has a good heart. He helped me with my problems and took the time for me. Subbed + Liked

  • @curwenarthurs6901
    @curwenarthurs6901 2 ปีที่แล้ว +8

    Excellent video. It helped me to easily understand how to dynamically create HTML using JS and to render it using the DOM. Thanks!

  • @minimotivates
    @minimotivates 2 ปีที่แล้ว +3

    Very concise and clear, absolutely perfect explanation speed.

  • @ektatiwari9969
    @ektatiwari9969 6 หลายเดือนก่อน

    best explained and to the point i have searched alott but do not able to fetch the record from json file... but u are saviour thanks a tonnnnnnn ❣❣..if someone watched this and follow the steps no other video is required.

  • @AYOUB_Ak1887
    @AYOUB_Ak1887 5 หลายเดือนก่อน

    Thank you my Indian brother for best teaching ❤

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  5 หลายเดือนก่อน

      Thank you, but i am actually from Greece.

    • @AYOUB_Ak1887
      @AYOUB_Ak1887 5 หลายเดือนก่อน

      @@DigitalFox-tutorials Excuse me bro , I thinked you are from India 😅🤦🏻‍♂️

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  5 หลายเดือนก่อน

      No worries, we are all brothers.

  • @stripewarrior
    @stripewarrior 5 หลายเดือนก่อน

    Best video I have found on this. Thank you. Vamos Greece ❤️

  • @rohitchowdhury2660
    @rohitchowdhury2660 ปีที่แล้ว +1

    great it helped bro! I have been wondering for 2 days for this.

  • @crackrokmccaib
    @crackrokmccaib 2 ปีที่แล้ว +3

    Awesome job explaining this. You made it so easy to understand. I wish I could give more than one 👍.

  • @SomeOne-rx2xw
    @SomeOne-rx2xw 2 ปีที่แล้ว +1

    very straightforward and well explained thanks man!

  • @Mahesh717
    @Mahesh717 2 ปีที่แล้ว +1

    very helpful with clear explanation👍

  • @shubhambargude
    @shubhambargude 2 ปีที่แล้ว +1

    Very simple and detailed tutorial

  • @rajas2214
    @rajas2214 ปีที่แล้ว

    thankyou so much, good explanation. i expected more videos in JSON

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว +1

      Thank you.
      I have more videos on how to work with JSON files on my channel. Check them out:
      th-cam.com/video/0Nw1GvtmblY/w-d-xo.html
      th-cam.com/video/TMAwyq14FUI/w-d-xo.html

  • @forester1
    @forester1 2 ปีที่แล้ว +1

    Always a perfect tutorial.
    Thank you 💓

  • @siberiatrekking
    @siberiatrekking 11 หลายเดือนก่อน

    Very clear tutorial, thanks!

  • @KHALEDMORSHED
    @KHALEDMORSHED 2 ปีที่แล้ว

    Well explained. It helps me lot. Manu many thanks brother.

  • @AbbasAli-yj3fg
    @AbbasAli-yj3fg 2 ปีที่แล้ว

    love you man
    you saved my S 😅😅

  • @absbi0000
    @absbi0000 ปีที่แล้ว

    awesome tutorial. thank you so much man!

  • @eduardotejeda
    @eduardotejeda ปีที่แล้ว

    Thanks, man. Great explanation.

  • @bbhoxe
    @bbhoxe 2 ปีที่แล้ว

    That's a brilliant tutorial, thank you so much!

  • @gregrosenquist664
    @gregrosenquist664 2 ปีที่แล้ว

    very basic and perfect for my learning requirements at the moment. Regards.

  • @LordmkKING67
    @LordmkKING67 ปีที่แล้ว +1

    Thankfully i didnt go all the way by myself, would have been huge. So thanks for simplyfying. It displays things as it was written ${something.name} instead of the actual data however..

  • @tosaponintaraumnauy1053
    @tosaponintaraumnauy1053 2 ปีที่แล้ว

    thank you very much sir. >>ขอบคุณมากๆเลยครับ

  • @Cadknowledge
    @Cadknowledge 2 ปีที่แล้ว

    subscribed your channel awesome content thanks bro this is what i am looking for

  • @TurielD
    @TurielD 2 ปีที่แล้ว +1

    Hmm, I tried to recreate this, and I I get is a header line.
    Then i tried downloading your original code to run that - and all i get is the header line, no products.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Hey, do you run the code from inside your localhost server. If not it will not work.

  • @ozydeus6867
    @ozydeus6867 2 ปีที่แล้ว

    You are heaven sent! Exactly what I've been looking for. Do you have tutorial on how to add JSON entries from user input (Add/Update/Delete)?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Thank you, check this out th-cam.com/video/HyyAg0cI5N8/w-d-xo.html

    • @ozydeus6867
      @ozydeus6867 2 ปีที่แล้ว +1

      @@DigitalFox-tutorials Is it possible using javascript only? I'm trying to work my way around github pages, php is not yet allowed to be hosted.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว +1

      Sorry, you can't manipulate files with javascript, you need a server side language to do that.

    • @keanugives
      @keanugives 2 ปีที่แล้ว +1

      @@DigitalFox-tutorials I see. So in order to add key pairs to JSON it has to be added manually? Cannot add via code except PHP?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      I am saying that if you want to write data in a file you have to use a server-side language like PHP, or you can use node.js. But you can not use javascript alone for this.
      Check this out. th-cam.com/video/lT0w3pzZz4w/w-d-xo.html

  • @beticohernandez9536
    @beticohernandez9536 2 ปีที่แล้ว

    No hiciste el editar y eliminar?

  • @IDrKongoI
    @IDrKongoI 2 ปีที่แล้ว

    Wow i searched Hours to find a Way and the Solution is in an 4min Video.
    Awesome thank you.
    Is there a Way to do this with mutiple jsons ? Tried promise.all but cant figure out, how to store each json separat.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว +1

      Hey thanks, i am sure there is a way to fetch data from multiple JSON files, but i didn't done it so far, i will think this over and i will get back to you.

  • @chlwodlr999
    @chlwodlr999 2 ปีที่แล้ว

    very helpful video
    could you tell me the reason why you used queryselecter?
    im still in a basic step

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว +1

      Hey, with the querySelector method we can target any html element like we do with css.
      Check this out: developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

  • @sebastianschomig8708
    @sebastianschomig8708 2 ปีที่แล้ว +1

    hey is there a way to use .json offline? i want to make a app for mobile phone including a function like this. i need to load and store data from/to a .json to show in my index.html. the problem i got is, i want that application as an offline-app. do you have a solution for my problem?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Hey, yes you can. If the json file is on your applications root folder and not in a remote location i don't see any problem

  • @FrankGP.Systems
    @FrankGP.Systems 2 ปีที่แล้ว

    thankyou for source code download !

  • @ceketuveux
    @ceketuveux 3 หลายเดือนก่อน

    Thank you so much for this video. I have a question i could not solved since 3 days. How would i do to target only ONE image and style it in CSS ? For example if i want to change the width of the 2 second image ("id":2). How would i proceed ? Been searching answers for days..

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  3 หลายเดือนก่อน

      I am glad you liked the video, thank you. Now based on my code you can target the second image from the CSS file like this:
      table tr:nth-child(2) img{
      width: 100%;
      }
      The above css code means that we are targeting every image in the second table row and set the width to 100%
      Hope it helps.

    • @ceketuveux
      @ceketuveux 3 หลายเดือนก่อน

      @@DigitalFox-tutorials Oh my god it is working! Amazing thank you so much. Do you know if it is possible to target any img in the DOM ? I tried desperately to target an img by changing the attribute/ID of any of those, but did not find how. I tried to use the "id" and "name" from the Json object properties to target one of those img but it did not work. Do you know if it is possible ?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  3 หลายเดือนก่อน +1

      You can change the number of the tr:nth-child to target the image you want:
      table tr:nth-child(3) img{
      width: 100%;
      } // Targeting the third image. This is one way
      or you can ad - in the javascript file - ad an id attribute to the image tag combining text and the id property from the JSON file.
      and target the image you want using css like this:
      #image-id-1{
      border: thin solid red;
      }
      #image-id-2{
      border: thin solid blue;
      }
      #image-id-3 ... and so on... you get the point.

    • @ceketuveux
      @ceketuveux 2 หลายเดือนก่อน

      @@DigitalFox-tutorials Thank you so much, coffees on me. I wonder what is the point by doing all that on Javascript when you can do it with HTML/CSS ?

  • @rajurastogi6822
    @rajurastogi6822 2 ปีที่แล้ว +1

    how do I escape hyphen in Key name ? It's giving me reference error and string/bracket Notation is not working.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Let's say this is the JSON key, value pair: "product-name": "Orient Vita Pro 28"
      You access the key like this: ${product["product-name"]}. I hope this is what you'r asking.

    • @rajurastogi6822
      @rajurastogi6822 2 ปีที่แล้ว

      @@DigitalFox-tutorials Thanks, this works.

  • @shridharshikalgar9641
    @shridharshikalgar9641 2 ปีที่แล้ว

    Excellent

  • @Willydmq
    @Willydmq ปีที่แล้ว

    Súper entendible amigo!! Pregunta? Si quiero que el último producto no salga que debo hacer?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว +1

      Before the for-of loop you can say products.pop(). This will remove the last object from
      the products array.
      products.pop();
      for(let product of products){
      out += `

      ${product.name}
      ${product.price}
      ${product.inventory}
      ${product.productCode}
      `;
      }

    • @Willydmq
      @Willydmq ปีที่แล้ว

      @@DigitalFox-tutorials súper te agradezco amigo 👊

  • @giapnguyen6693
    @giapnguyen6693 ปีที่แล้ว +1

    I've tried to put in the table and onchange function but it only work on the first row any solution:(

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Hey, let me take a look at your code.

    • @giapnguyen6693
      @giapnguyen6693 ปีที่แล้ว

      @@DigitalFox-tutorials
      function chon(){
      var x = document.getElementById("chon").value;
      document.getElementById("demo").innerHTML= x;
      };
      fetch("db/employees.json")
      .then(function(response){
      return response.json();
      })
      .then(function(employees){
      let placeholder = document.querySelector("#Employees-table");
      let out = "";
      for(let employee of employees){
      var n=0;
      n=n+1;
      out += `

      ${employee.stt}
      ${employee.name}
      ${employee.phone}
      ${employee.email}


      Thực tập
      Nhân viên
      Chuyên viên


      `;
      }
      placeholder.innerHTML = out;
      });

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      You are not closing the select element and the table cell that holds the select menu.

      Thực tập
      Nhân viên
      Chuyên viên

      Try again. Hope it works.

    • @giapnguyen6693
      @giapnguyen6693 ปีที่แล้ว

      @@DigitalFox-tutorials tks i've tried it but it still doesnt work 😢

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      You are applying the same id in every select menu. Every id in a page must be unique.
      Try this:
      Remove the id from the select menu, and pass-in as an argument 'this.value' to capture the value.
      And change the chon() function like this:
      function chon(value){
      document.getElementById("demo").innerHTML= value;
      };
      If this is not working zip your files and send them to digitalfox.tutorials@gmail.com, so i can see the whole project.

  • @Johan87577
    @Johan87577 2 ปีที่แล้ว +1

    I tried to follow along but even after downloading your source files, it still doesn't display any but the table (no data in the tables)

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Hey, are you running the code from your local server?? If not, it will not work.

  • @SlametRiyadi-rj1um
    @SlametRiyadi-rj1um 3 หลายเดือนก่อน

    You running your html on the webserver right?

  • @javierguajardo1760
    @javierguajardo1760 ปีที่แล้ว

    Nice thank you

  • @crackrokmccaib
    @crackrokmccaib 2 ปีที่แล้ว

    This doesn't work for me. I get this error
    from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Hey, where do you run the code? Are you fetching the JSON data from a remote location?

  • @niteshjaiswar7805
    @niteshjaiswar7805 ปีที่แล้ว

    Helpful+++

  • @Sara-vk4sp
    @Sara-vk4sp ปีที่แล้ว

    Thank you so much!!!

  • @Bowlingkegel97
    @Bowlingkegel97 ปีที่แล้ว +1

    my code is not working :( even after i download your files it just shows the table rows without data what am i doing wrong im on macbook i tried chrome EDIT: It works on mamp only.. which is weird. it does not work locally. what can i do

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      It's not weird, the script needs a local server to run. When we are dealing with http request we need a server to handle the request to serve us the data that we requested. In my opinion everything you build, even it's only html and css, you have to do it in your local server. Think about this: you have finished a simple website with html, css, and a little bit of javascript. Where do you upload it? On a server.

    • @Bowlingkegel97
      @Bowlingkegel97 ปีที่แล้ว

      @@DigitalFox-tutorials Youre a gem thank you for responding also so quickly..!. May i contact you for a simple question regarding my assessment?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Yes, but i don't always have the time to respond right away.

  • @mauarou4172
    @mauarou4172 ปีที่แล้ว

    nice thankYou

  • @Aida-s7f
    @Aida-s7f ปีที่แล้ว

    is there any link that should be posted in head section, cause when I open index.html in browser there is no table, only header

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Hey, You have to run the files from your localhost server

    • @Aida-s7f
      @Aida-s7f ปีที่แล้ว

      @@DigitalFox-tutorials I did. I've done already some small projects and wanted to try this table. Everything is in one folder, I open in from that folder, but no table in browser.
      I tried to add link from bootstrap, thinking that maybe code is from there and has to have link, but didn't help.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Download the source code to see if anything changes.
      digitalfox-tutorials.com/tutorial.php?title=Display-JSON-data-in-HTML-table-using-JavaScript

    • @Aida-s7f
      @Aida-s7f ปีที่แล้ว

      @@DigitalFox-tutorials source code is the one I used and put everything in local folder. I didn't type code myself.
      I don't know what could be wrong. Is there anything that should be downloaded or linked in like bootstrap?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      There is noting else. Are you sure you run the code from inside you localhost server?

  • @souradipmukherjee6986
    @souradipmukherjee6986 8 หลายเดือนก่อน

    The data object is printing its property values in console but on the webpage its printing undefined.....why is that happening

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  8 หลายเดือนก่อน

      Hey, check the values in the for-of loop for any typos.
      ${product.name}
      ${product.price}
      ${product.inventory}
      ${product.productCode}

  • @marcoangeli5476
    @marcoangeli5476 9 วันที่ผ่านมา

    Same process getting JSON fron an URL?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  22 ชั่วโมงที่ผ่านมา

      Yes but, the URL provided in the fetch method should be accessible, and CORS (Cross-Origin Resource Sharing) must be enabled on the server if you are fetching data from a different domain.

  • @lance_oquendo
    @lance_oquendo ปีที่แล้ว

    What if the JSON file starts with object? for example
    {info:
    [
    {
    "id":1
    },
    {
    "id":2
    }
    ]
    }

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      In this case you have to loop through the "info" object like this:
      for(let product of products.info){
      // output products
      }
      Also you have to use quotes around "info".
      Thanks good question.

    • @lance_oquendo
      @lance_oquendo ปีที่แล้ว +1

      ​@@DigitalFox-tutorialsthank you so much! I did it 🎉

  • @drakencraft1
    @drakencraft1 ปีที่แล้ว

    Hi, I downloaded your source file, but still I cant see json file in html, just lables. please help

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      You have to run the files from your local server. Read the comments below this will help you.

    • @drakencraft1
      @drakencraft1 ปีที่แล้ว +1

      @@DigitalFox-tutorials ou, thank you for fast answer. Is there some way how to do it locally? I can pull .json file from database, but I want to show it in html?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      Running the code locally means, running the code in your computer and not in a remote server. But in order to run the tutorial's code locally, you have to install a local server like mamp or xampp in your computer, and run the files from inside the local's server directory.

  • @وليدالنادي-ح3ق
    @وليدالنادي-ح3ق ปีที่แล้ว

    Thanks A Lot

  • @abhyudayshukla8732
    @abhyudayshukla8732 2 ปีที่แล้ว +1

    I tried with this code but not able to see html table

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Hey maybe you got a typo in your code.
      Download the code from my website and test it out.
      digitalfox-tutorials.com/tutorial.php?title=Display-JSON-data-in-HTML-table-using-JavaScript

    • @abhyudayshukla8732
      @abhyudayshukla8732 2 ปีที่แล้ว

      @@DigitalFox-tutorials No typo error I checked twice. It's not working.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  2 ปีที่แล้ว

      Do you have a local server installed on your computer like WAMP or XAMPP. Or if you run the code on a live server in VS code it will not work.

    • @hdquemada
      @hdquemada 2 ปีที่แล้ว

      @@DigitalFox-tutorials How would I be able to get it to work on a local server? I am using this example to learn further how to work with html, css and js, and it would be very helpful to be able to run this locally. It looks like other might benefit from this too.

  • @sanchitsharma2899
    @sanchitsharma2899 ปีที่แล้ว

    Uncaught (in promise) TypeError: Cannot set properties of null (setting 'innerHTML')
    Its showing this error even I tried put the script tag below table tag but not working.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  ปีที่แล้ว

      I think that you maybe have a type error somewhere in your code.
      Download the source code and try again.
      digitalfox-tutorials.com/tutorial.php?title=Display-JSON-data-in-HTML-table-using-JavaScript
      Do you run the code from your local server?

  • @kindyletutorials7197
    @kindyletutorials7197 ปีที่แล้ว

    1000000000000000000000 thanks bro.

  • @206010613
    @206010613 ปีที่แล้ว

    Hey, I copied the code as it is on your site, but I still get the "Uncaught TypeError: Failed to fetch" the script.js. Just installed python do I need to install some libraries?

    • @larsiparsii
      @larsiparsii ปีที่แล้ว

      I know it's a late reply, but why are you using Python? This is for JavaScript/HTML.

    • @206010613
      @206010613 ปีที่แล้ว

      I don't understand @@larsiparsii

  • @nicoleuruchima595
    @nicoleuruchima595 2 ปีที่แล้ว

    THANKS!

  • @chansamonejk5379
    @chansamonejk5379 2 ปีที่แล้ว

    thank you

  • @AvliyoqulovBaxrom
    @AvliyoqulovBaxrom 9 หลายเดือนก่อน

    GUY WHO CAN HELP ME GET FULL CODE

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  9 หลายเดือนก่อน +1

      Get the code from my website:
      digitalfox-tutorials.com/tutorial.php?title=Display-JSON-data-in-HTML-table-using-JavaScript

  • @developer2526
    @developer2526 11 หลายเดือนก่อน

    css file

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  11 หลายเดือนก่อน +1

      Get the source code from here:
      digitalfox-tutorials.com/tutorial.php?title=Display-JSON-data-in-HTML-table-using-JavaScript