In general, there is code to add values ​​from json to div blocks.

`$(document).ready(function(){ $.ajax({ url: 'ajax/prop', dataType: 'html', success:function(data){ var jsonStr = JSON.parse(data); const container= document.getElementById('prop'); jsonStr.forEach(function(item) { const itemDiv = document.createElement('button'); itemDiv.classList.add('btn'); itemDiv.id = item.id; let innerHtml = '<dl>'; Object.keys(item).forEach(function(key) { innerHtml += ` <dd>${item[key]}<dd> ; }); innerHtml += '</dl>'; itemDiv.innerHTML = innerHtml; container.appendChild(itemDiv); }); } });` 

But the problem is that all values ​​are added only to the first div, and I need the first value from json to be added to the first div, the second to the second, etc. Here is a line from json. {"id":"1","time":"2 минуты"},{"id":"2","button":"Купить"},{"id":"3","back":"Вернуть"},{"id":"4","time":"1 минута"}

  • Did you try to add any conditions? - Kel Fish
  • The code does not look like a worker. In dataType, you can specify json, not html and do not parse. - holden321
  • if you have an object, you can simply iterate over it and output it by index, if an array, then you shouldn't index it) - Pavel Igorevich
  • @Pavel is an object, but I don’t know where to insert a loop for iterating over objects with one class - Artem

0