Submit without reloading page cakephp

Asked

Viewed 91 times

0

How do I give Ubmit to pages without reloading with cakephp?

1 answer

1


You can use jQuery.ajax and jQuery.serialize, thus:

<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(function() {
    var meuForm = $("#meuForm");
    meuForm.submit(function() {
        $.ajax(meuForm.attr("action"), {
            "type": meuForm.attr("type"),
            "data": meuForm.serialize()
        }).done(function(resultado) {
            //Troque isto pela sua mensagem customizada
            alert(resultado);
        }).fail(function(error) {
            //Troque isto pela sua mensagem customizada de erro
            alert(error);
        });
    });
});
</script>

<form id="meuForm" method="POST" action="/sua rota cakephp">
    <input name="campo1" value="">
    <input name="campo2" value="">
    <button type="submit">Enviar</button>
</form>
  • Cake has no tool to simplify the use?

Browser other questions tagged

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