Form data is not sent with event.preventDefault ()

0

When submitting a form, I am using ajax and event.preventDefault() so the screen will not be reloaded. In my project, I made a small MVC structure, where the URL that step is the path that leads to the desired controller.

When I submit the form via POST without event.preventDefault() everything works normally. But when I put such code, nothing happens in the system, as if the form data were not sent. I'm breaking my head with it.

Here is the snippet of code:

$(document).ready(function() {

    $('form').submit(function(event){ 
            var formDados = jQuery(this).serialize();

            $.ajax({
                type        : 'POST', 
                url         : 'http://127.0.0.1/projeto/index.php?path=capacitacao/adm',
                data        : formDados,
                dataType    : 'json',
                encode      : true,
                success:function(result){
                    console.log(result);
                }
            })
            event.preventDefault();

    });
});
    
asked by anonymous 16.10.2017 / 09:37

1 answer

0

So try replacing "success" with "done" and added "fail", you can take action from your form so when you activate "submit" it will have nowhere to go.

$(document).ready(function() {    
    $('form').submit(function(event){

            event.preventDefault();

            var formDados = $(this).serialize();

            $.ajax({
                type        : 'POST', 
                url         : 'http://127.0.0.1/projeto/index.php?path=capacitacao/adm',
                data        : formDados

            }).done(function(response){

                 console.log(response);

            }).fail(function(result) {

                  console.log(result);

            });
});
    
16.10.2017 / 12:52