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);

                            } 
                        }});
  • Try console.log inside setTimeout function to check either it is coming inside it or not. – Kamal Paliwal Nov 12 '18 at 13:36
  • Yes.it is coming inside – Mahi M Nov 12 '18 at 13:38
  • Try assigning an id to your message div and then remove it by $("#id").remove(); – Kamal Paliwal Nov 12 '18 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 – CompactCode Nov 12 '18 at 14:33
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);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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