D
D
Dc8882016-01-13 18:59:37
JSON
Dc888, 2016-01-13 18:59:37

How to properly implement json loading?

How to properly implement json loading? The essence of the question is that: let's say there is a json load. and there is html where the whole thing is inserted - let's say

<div>
<div>Новость 1</div>
<div>Содержание новости</div>
<img // >
</div>

Here, for example, how to make it so that if there is not enough information in the database (pictures or the name of the news), then html would not be typed on it either .... Otherwise, there remains a stupidly bare block - this is not beautiful ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Dragalev, 2016-01-13
@vladqwerty

If you receive a response from the database and implement your code for manipulating the DOM, then just make a loop with a check, for example, for the existence of the image field in the news object if(news[i].image) {...} and, accordingly, if there is something - add to the structure, if not, then exit the subroutine and check further.
upd. If an empty value comes from the database in the image field (or any other), then check not the existence of this field, but its contents)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question