A
A
Alexey Chertok2018-04-24 14:06:05
JavaScript
Alexey Chertok, 2018-04-24 14:06:05

How to get last element via getJSON?

Good afternoon.

In general, I decided to make AJAX loading of news. Implemented everything that I wanted in principle, i.e. for example, when adding news, it immediately appears in the block. But the problem is that this reloads the entire container.

Code example:

<div class="newsContainer--list">
    <div class="newsContainer--element">Сама новость</div>
</div>


So when I get result from php I update the container like this:
$.getJSON('/?module=news&media=ajax&action=json_load_news', function(data){
    $('.newsContainer--list').replaceWith($('.newsContainer--list').html(data));
});


And when an update occurs, the entire newsContainer--list container is understandably reloaded. Is it possible to somehow make sure that the entire container is not overloaded, but just at the beginning of it new news is appended?

I would be very grateful in advance if anyone can help/help me.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Pyrkin, 2018-04-24
@ps1panda

$('.newsContainer--list').replaceWith($('.newsContainer--list').html(data));

you update the entire block with this code,
you need to do it through something like this)

I
Ivan, 2018-04-24
@LiguidCool

$.append()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question