Display Dialog (Materialize) with ajax without clicking the button

Asked

Viewed 157 times

0

Guys, I’m building a ticket system and I’ve decided to exchange a closed ticket message alert for a dialog, would be the Toast materialize.com. However, I am not able to make it return already executed, without having to click the button to do so as in the materialize site.

The java/ajax code is this.

$(function() {
            $(".fechar").click(function(){
                var element = $(this);
                var select_ticket = element.attr("close");
                var select_table = element.attr("ticket_table");
                var mail = element.attr("mail");
                var info = {
                    'close': select_ticket,
                    'ticket_table': select_table,
                    'mail': mail
                }
                if(confirm('Tem certeza que deseja fechar o ticket?'))
                {
                    $.ajax({
                        type: "POST",
                        url: "assets/inc/del/ticket.php",
                        data: info,
                        success: function(){
                            alert("Fechado com sucesso!");
                        }
                    });
                }
                return false;
            });
        });
  • How are you invoking this dialog?

  • On the site of materialize, they give this code <a class="btn" onclick="Materialize.toast('I am a toast!', 3000, 'rounded')">Toast!</a> but you need to have a onclick to execute. Only that my intention is that when making the change in the bank it already return the dialog executed, without the need to click the button.

1 answer

1


Just replace alert("Fechado com sucesso!"); for Materialize.toast('Fechado com sucesso!', 4000)

<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>

<script>
     Materialize.toast('Ticket Fechado!', 4000);
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.