D
D
Danya Kozlovskiy2020-09-22 12:07:26
HTML
Danya Kozlovskiy, 2020-09-22 12:07:26

How to get json file by reference to html table?

Hello, you need to get a json file from a link, then convert it to a human form so that you can work with its values ​​and output it to an html table. But I don't know how to do it. Reading questions like this only produced errors in the console or empty output. Preferably with comments on what and why we are doing, if possible.

JSON is on the site in this form:

[{"price":10201,"quantity":4,"name":"\u0421\u0442\u0443\u043b \u043e\u0444\u0438\u0441\u043d\u044b\u0439"},{"price":12862,"quantity":5,"name":"\u041c\u0430\u0440\u043a\u0435\u0440\u044b \u043e\u0444\u0438\u0441\u043d\u044b\u0435"},{"price":15523,"quantity":6,"name":"\u041a\u0430\u043d\u0446\u0435\u043b\u044f\u0440\u0441\u043a\u0438\u0439 \u043d\u0430\u0431\u043e\u0440"},{"price":16411,"quantity":6,"name":"\u0412\u043e\u0434\u0430 \u0431\u0443\u0442\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f"},{"price":15967,"quantity":6,"name":"\u0411\u0443\u043c\u0430\u0433\u0430 \u0434\u043b\u044f \u043f\u0440\u0438\u043d\u0442\u0435\u0440\u0430"},{"price":10201,"quantity":4,"name":"\u0428\u043a\u0430\u0444 \u043a\u043d\u0438\u0436\u043d\u044b\u0439"},{"price":17298,"quantity":6,"name":"\u0427\u0430\u0439\u043d\u0438\u043a \u044d\u043b\u0435\u043a\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439"},{"price":8870,"quantity":3,"name":"\u0421\u0432\u0435\u0442\u0438\u043b\u044c\u043d\u0438\u043a"},{"price":8870,"quantity":3,"name":"\u041c\u043e\u043d\u0438\u0442\u043e\u0440 22\u2033"},{"price":11975,"quantity":4,"name":"\u0421\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0431\u043b\u043e\u043a"},{"price":15523,"quantity":6,"name":"\u0414\u0432\u0435\u0440\u044c \u043c\u0435\u0436\u043a\u043e\u043c\u043d\u0430\u0442\u043d\u0430\u044f"},{"price":13749,"quantity":5,"name":"\u041b\u0430\u0437\u0435\u0440\u043d\u044b\u0439 \u043f\u0440\u0438\u043d\u0442\u0435\u0440"},{"price":14636,"quantity":5,"name":"\u0421\u0442\u043e\u043b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u044b\u0439"}]


Return data format, example:
[
  {
    "price": 9685,
    "quantity": 3,
    "name": "Бумага для принтера"
  },
  {
    "price": 13896,
    "quantity": 5,
    "name": "Шкаф книжный"
  },
  {
    "price": 14739,
    "quantity": 5,
    "name": "Канцелярский набор"
  }
]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tim, 2020-09-22
@morto

$.ajax({
  method: 'GET',
  url: 'https://jsonplaceholder.typicode.com/users',
  dataType: 'json',
  success: data => {
    console.log(data)
   //тут работаем с data. это преобразованный json которую мы получили в ответ от сервера
   // проходим циклом и выводим в таблицу нужные данные
  }
})

D
Denis Melnikov, 2020-09-22
@Mi11er

We read JSON, make a table in a loop, push it into the DOM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question