JQuery AJAX: how to add a "SAVED" message and make it disappear after the second

this is probably very simple for a jQuery expert.

I have <div id = "form23"> <form <textarea> blahblah </textarea> <input type = "button" value = "save" OnClick = "saveCaption (23)"> </ form> </DIV>

I want the SAVED message to appear and disappear. But I do NOT want the form or its elements to disappear.

I have an AJAX call that looks like this.

function saveCaption(id) {

var queryString = $('#form'+id).formSerialize(); 

  $.ajax({

    type: "POST",

    url: "includes/ajax.php?request=saveCaption",

    data: queryString,

    success: function(response) {

      $('#form'+id).append(response)

    }

  });

  return false;

}

I was wondering ... I can add an answer. But is there a way to disappear right after the second. Right now, he just keeps repeating and adding to the last addition. I would like it to appear and disappear immediately after using fadeOut.

: IV RaYell. ... ?

saveCaption (id) {

var queryString = $('#form'+id).formSerialize(); 

  $.ajax({

    type: "POST",

    url: "includes/ajax.php?request=saveCaption",

    data: queryString,

    success: function(response) {

        $('#form'+id).append('<div id="message">'+response+'</div>');

        setTimeout(function () {

          $('#message').fadeOut(function(){

            $(this).remove();

          });

        }, 1000);

    }

  });

  return false;

}

+3
2

, RaYell , fadeOut, - , , . - :

setTimeout(function () {
  $('selector').fadeOut(function(){
    $(this).remove();
  });
}, 1000);
+4

( ):

setTimeout(function () {
    $('selector').fadeOut();
}, 1000);

-, .

+3

Source: https://habr.com/ru/post/1715258/


All Articles