Read JSON File into HTML with JavaScript Fetch API

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024
  • НаукаНаука

Комментарии • 40

  • @ankitpatil8568
    @ankitpatil8568 Год назад +4

    I searched the entire internet to solve this problem, but the solution was as simple as turning on live server. Thank You!

  • @НадеждаГришко-т8ъ
    @НадеждаГришко-т8ъ Год назад +7

    This is the only video out of 30 watched that helped me solve the problem! Why hasn't anyone talked about a live server before? And everything turned out to be so simple. Thanks a lot to the author!

    • @Z3r0_B7i55
      @Z3r0_B7i55 11 месяцев назад

      How much do you get paid to write fake replies? Just curious...

    • @НадеждаГришко-т8ъ
      @НадеждаГришко-т8ъ 11 месяцев назад

      @@Z3r0_B7i55 If I got paid for commenting it would be nice

  • @DemsterDog
    @DemsterDog 4 месяца назад +1

    You've been a big help man, thank you!

  • @thierrynoemy8344
    @thierrynoemy8344 9 месяцев назад +1

    Thank you! that's exactly I need now👍

  • @ByteGrad
    @ByteGrad  2 года назад

    Hi, mastering JavaScript is critical if you want to be a modern, professional developer: www.udemy.com/course/professional-javascript-course/?referralCode=0C1D5752923168BC87C2
    Also, if you are a front-end developer then mastering CSS (including Flexbox, CSS Grid, etc.) is equally important: www.udemy.com/course/professional-css/?referralCode=4C3C08E82629E6B15752

  • @SalientAnimal
    @SalientAnimal 7 месяцев назад +1

    Why would I be getting the error "Uncaught (in promise) TypeError: data.forEach is not a function". My code is exactly as the video, except my data is from a live API link. I'm using FireFox as a Web Browser.

    • @MaxNadeev
      @MaxNadeev 7 месяцев назад

      Same problem

    • @162sujiths4
      @162sujiths4 3 месяца назад

      If the data item is in the form of HTML Collection then it displays this error. Convert the HTML collection to Array by using Array.from() method then apply forEach method.

  • @umangternate
    @umangternate Год назад +1

    How to save the data in a variable?

  • @rithikop3203
    @rithikop3203 11 месяцев назад +1

    The list prints undefined in webpage

  • @ramandamytv1193
    @ramandamytv1193 Год назад +1

    thank you very much!

  • @ayushmaansingh5568
    @ayushmaansingh5568 8 месяцев назад

    IT WORKED THANK YOUUUU LOVE YOUUUUU

  • @Knards
    @Knards 2 месяца назад

    I have tried writing form data to a json file, but never was successful. Even using this author's tutorial to do it. Why doesnt anyone teach real world examples like reading and writing to a local json file?

  • @maisserhan
    @maisserhan 20 дней назад

    how can add new object in json

  • @vidyays6161
    @vidyays6161 2 месяца назад

    Hey how can I show the api data on screen in a check box. once user selects teh check box it should insert in database

    • @vidyays6161
      @vidyays6161 2 месяца назад

      Anybody knows pls help me to do that

  • @SoIam-eb4sf
    @SoIam-eb4sf Год назад

    no....... Hey what i want is get json data as JS without using copy of json file . What I want is to use API From website and use online web page data on my web page.

  • @VidhyaShreeK-d8l
    @VidhyaShreeK-d8l Год назад +1

    thank you sir

  • @gappuma7883
    @gappuma7883 Год назад

    Do you know if it's a good practice to read directly from a Json file stored on the server or should i put it in a database for security reasons. Or is there a way to store it securely?

  • @hassanhaider8710
    @hassanhaider8710 8 месяцев назад

    Thank you bossman

  • @01Bluedragon
    @01Bluedragon 2 месяца назад

    I keep getting this error "TypeError: data.foreach is not a function" can you please help?

    const listEL = document.querySelector('ul');
    fetch('./messages.json')
    .then(res => res.json())
    .then(data => {
    console.log(data);
    /*data = JSON.parse(data);*/
    data.foreach(post =>{
    listEL.insertAdjacentHTML('beforeend',`${post.sender_name}`);
    });
    /*listEL.insertAdjacentHTML('beforeend',`test`);*/
    });

  • @PranavIngale-z2b
    @PranavIngale-z2b Год назад

    i am getting values as undefined

  • @Felipekimst
    @Felipekimst Год назад

    hii! do you know why is my res.json() request returning a forever pending status request?? it doesnt reject nor resolve, so the .then and .catch aren't being triggered

    • @ByteGrad
      @ByteGrad  Год назад +1

      Hi, sorry I don’t have the time to give you a good answer. I highly recommend going through my Professional JavaScript course - these things will become easy to solve

    • @Felipekimst
      @Felipekimst Год назад +1

      @@ByteGradthanks for replying, bro! I managed to fix the problem, turns out the json file had a syntax error but for some reason I don't know, it didn't throw an error lol but everything is okay now haha

  • @cimmik
    @cimmik Год назад

    Why does the live server solve the CORS error?

    • @ByteGrad
      @ByteGrad  Год назад

      I think you just need any server to serve the JSON-file. In local development here we create one with the Live-Server extension. Probably because it can be insecure to allow local files to be fetched, so you need to explicitly serve it from a server. That's why the error mentions it supports and schemes but not file://.

    • @cimmik
      @cimmik Год назад +1

      @@ByteGrad Interesting and thanks for the response. I'm tinkering on how I can automate some of my tasks at my workplace by making a web app to read a JSON file instead of manually working in large excel sheets. My workplace's file system is connected to a cloud. I don't know if there's an API available that could give my app access to the file system

  • @klaasvanamsterdam3061
    @klaasvanamsterdam3061 Год назад

    First, I get only ${post.title} rows, but later i see, must use the template marks there. Thanks!

    • @ByteGrad
      @ByteGrad  Год назад +1

      Are you using backticks instead of quotation marks?

    • @klaasvanamsterdam3061
      @klaasvanamsterdam3061 Год назад +1

      @@ByteGrad Yes, I used the wrong marks. It wasn't until I found out about a "template" insert that I understood as a beginner what I was doing wrong. Thanks again for all the tutorials.

  • @juniorpaez2654
    @juniorpaez2654 2 года назад

    Hi! i don't speack english, so sorry!
    But, i have a qustion
    in the next code:
    function obtenerEmpleados() {
    const archivo = './empleados.json'
    fetch(archivo)
    .then(resultado => {
    console.log(resultado)
    })
    }
    obtenerEmpleados();
    i get a status: 404 in the console
    i think the const archivo the read like string
    i have this json
    {
    "empleados": [
    {
    "id": 1,
    "nombre": "Steven",
    "puesto": "Programador Web"
    },
    {
    "id": 2,
    "nombre": "Héctor",
    "puesto": "Programador BackEnd"
    },
    {
    "id": 3,
    "nombre": "Elizabeth",
    "puesto": "Diseñadora"
    },
    {
    "id": 4,
    "nombre": "Junior",
    "puesto": "Jefe de Área"
    }
    ]
    }
    Help me, please!

    • @ByteGrad
      @ByteGrad  2 года назад

      Hi, 404 means it can’t find that file. Is that file in another folder?

    • @juniorpaez2654
      @juniorpaez2654 2 года назад

      @@ByteGrad No, I have in the same folder

    • @ByteGrad
      @ByteGrad  2 года назад +1

      You could try writing the exact same as me in the video (including semicolons), make sure it works and then change it with your own JSON data

  • @florianmaier9221
    @florianmaier9221 Год назад +1

    Thank you so much!