M
M
misc12015-01-15 14:37:10
JavaScript
misc1, 2015-01-15 14:37:10

How to display the result separately?

good time of day). There is JS:

$(document).ready(function() {
$.ajax({
url: "data.json",
dataType: "text",
success: function(data) {

var json = $.parseJSON(data);
$.each(json, function(key,value) {
document.write('<div id="post">' + value.name + '</div>');
}); 
 }
});
});

And JSON:
{"post1":{"name":"Hello!","rating":1,"img":"/p1.jpg"},"post2":{"name":"Launch new service","rating":1,"img":"/p2.jpg"}}

As you can see from the JS, the name of all posts is read and put into one div, as a result we get in #post:
Hello!Launch new service

Is there any way to get this out separately? That is, post1 is in its own div, and post2 is in another div.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Taratin, 2015-01-15
@misc1

jsfiddle.net/QW01_01/44rgqLg6

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question