force a one-button event after deleting log via modal

0

I want to force a click on the panel after deleting a record via modal.

[!] [Description of the Panel] [1]] [1]

I need to immediately push the panel button shortly after deleting the file.

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');
        //=====>>>> aquii
       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});
    
asked by anonymous 19.02.2018 / 19:24

2 answers

1

Since you're using Materialize , just do it as follows:

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');

        /* Executa o evento de clique na "tab" */
        $("[href=\"#panel80\"]").click();


       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});

Example:

$("#btn").click( function() {
  $("[href=\"#panel80\"]").click();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><!--CompiledandminifiedCSS--><linkrel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script><divclass="row">
  <div class="col s12">
    <ul class="tabs">
      <li class="tab col s3"><a class="active" href="#test1">Test 1</a></li>
      <li class="tab col s3"><a href="#panel80">Test 2</a></li>
      <li class="tab col s3 disabled"><a href="#test3">Disabled Tab</a></li>
      <li class="tab col s3"><a href="#test4">Test 4</a></li>
    </ul>
  </div>
  <div id="test1" class="col s12">Test 1</div>
  <div id="panel80" class="col s12">Test 2</div>
  <div id="test3" class="col s12">Test 3</div>
  <div id="test4" class="col s12">Test 4</div>
</div>

<button id="btn" class="button">Acessar Tab 2</button>

If you want to refresh the page, just run: window.location.reload()

Example:

$('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');

        /* Recarrega a página */
        window.location.reload()


       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});
    
19.02.2018 / 19:33
0

Use trigger passing click as parameter.

 $('#btnDelteYes').click(function () {
    var id = $('#myModalDelete').data('id');    

    $.post('estrutura/excluirarquivo.php',{acao:'delete',id:id},function(r) { 
       var m = jQuery.parseJSON(r);        
       if (m.success) {         
        toastr["success"](m.msg);
        $('#myModalDelete').modal('hide');
        $('#seuBotao').trigger('click'); //id do seu botão
       } else {
        toastr["error"](m.msg);
        $('#myModalDelete').modal('hide');

       }
          hideMessage();
    });
});

$('#bt2').click(function(){
    alert('botao 2 clicado');
})

$('#bt1').click(function(){
   $('#bt2').trigger('click');

})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonid="bt1"> bt1 </button>
<button id="bt2" disabled> bt2 </button>
    
19.02.2018 / 19:31