Display Dialog (Materialize) with ajax without clicking the button

0

Well, I'm setting up a ticketing system and decided to switch the closed ticket message from a alert to a dialog, it would be toast of materialize.com. But I am not able to make it return already executed, without having to click the button for it as in the materialize website.

The code in java / ajax is that.

$(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;
            });
        });
    
asked by anonymous 21.12.2017 / 06:02

1 answer

1

Just replace alert("Fechado com sucesso!"); with 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><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>

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