0

I need to remove message after 2 sec but its not working

$.ajax({
                        'method': 'post',
                        'url': $form.attr('action'),
                        'dataType': 'json',
                        'data': $form.serialize(),
    'success': function (res) {
                                if (res.success) {
                                    $form.find('[type=submit]').removeAttr('disabled');
                                   var h = '<div class="message-success success message"><div>' + res.message + '</div></div>';
                                   $(h).insertBefore($form);
                                    $form.hide();
                                    setTimeout(function () {
                                        $(h).remove();

                                }, 2000);

                            } 
                        }});
4
  • Try console.log inside setTimeout function to check either it is coming inside it or not. Commented Nov 12, 2018 at 13:36
  • Yes.it is coming inside
    – Mahi M
    Commented Nov 12, 2018 at 13:38
  • Try assigning an id to your message div and then remove it by $("#id").remove(); Commented Nov 12, 2018 at 13:43
  • 1
    This is something you should post in the general stackoverflow. It does not have anything to do with Magento 2 and you will get a quicker and more accurate response there. FYI Commented Nov 12, 2018 at 14:33

1 Answer 1

0

you need to try the code like this.

    $form.find('[type=submit]').removeAttr('disabled');
    var h = '<div id="custommessage" class="message-success success message"><div>' + res.message + '</div></div>';
    $(h).insertBefore($form);
    $form.hide();
    setTimeout(function () {
         $('#custommessage').remove();
    }, 2000);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.