E
E
Evgeny Kramor2018-05-07 13:27:15
AJAX
Evgeny Kramor, 2018-05-07 13:27:15

How to properly return result in php/ajax?

Good afternoon. There is the following code:

function addPosts() {
            $.ajax({
                type: 'post',
                url: "/example.php",
                cache: false,
                response: 'text',
                success: function(data) {
                    $("#getNotice").html(data);
                }
            });
        }

After returning the data in #getNotice , you need to hide the data after a while. Tried delay(3000).fadeOut() but the whole problem is that after hiding they don't show up anymore.
It works as follows: the user clicks on the button and receives a notification that his data was successfully added, but when he clicks again, the notification does not come.
I considered show() and hide() , but it seems to me that I'm looking in the wrong place and not doing it quite right.
Thank you!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2018-05-07
@exgod

it's simple, you didn't think of it

success: function(data) {
                    $("#getNotice").html(data);
                    $("#getNotice").show(); // на уже показанный объект никак не влияет
                    $("#getNotice").fadeOut(3000); // фэйд в течение 3 сек.
                }

T
Troodi Larson, 2018-05-07
@troodi

You looked right, just hide it by timeout.

V
Vitaly, 2018-05-07
@rim89

setTimeout(function(){
$("#getNotice").addClass('hidden'); // добавить класс, который display: none;
}, 3000);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question