Add data by Codeigniter with Ajax

1

I'm new to MVC development and so far I'm having trouble identifying the error when trying to save my form records. Gives the error message: 403 (Forbidden). I'm using Codeigniter.

My role:

$(document).ready(function () {
    $('#btn-save').click(function () {
        var dados = $('#form').serialize();
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: "<?php echo base_url('index.php/centros/cadastrar');?>",
            async: true,
            data: dados,
            success: function (response) {
                location.reload();
            }
        });
        return false;
    });
});
});
    
asked by anonymous 22.05.2015 / 06:53

1 answer

0

Little information passed. Anyway, I'll try to help:

<script>
     $(document).ready(function() {
        $("#botao").click(function(e){
            e.preventDefault();
            var dados   = $('#formulario').serialize();
            $.ajax({
                type: "POST",
                url: "<?php echo site_url('centros/cadastrar'); ?>",
                data: dados,
                success: function(response){ 
                    // TODO faca algo  
                }, 
                error: function(response){
                    // TODO
                }
            });
        });
    });

</script>
Remember that the site_url ('centers / register') should be the targeting for the controller that will do the insertion.     
28.05.2015 / 23:01