Sucess Ajax does not work with Codeigniter Controller

Asked

Viewed 93 times

0

Good afternoon, I’m beginner in development.

I have a form whose I don’t want the page not to be reloaded when the user submits the form. for this I am using Ajax, I was able to perform the inclusion in the bank using codeigniter+ajax, however the instruction sucess ajax is not being invoked, I would like to know how to invoke it, I thank you already`

Controller

public function agendar()
{
        $data['nome'] = $this->input->post('nome');
        $data['email'] = $this->input->post('email');
        $data['celular'] = $this->input->post('celular');
        $data['dia'] = $this->input->post('dia');
        $data['hora'] = $this->input->post('hora');

        echo $this->db->insert('agenda',$data);

    }

Ajax

 $("#formulario").submit(function(event){
     event.preventDefault();
              $.ajax({
                       url: 'http://localhost/Odontologia/odonto/agendar',
                       type: 'POST',
                       data: {
                           nome: $('#nome').val(),
                           email: $('#email').val(),
                           celular: $('#txttelefone').val(),
                           dia: $('#dia').val(),
                           hora: $('#hora').val()
                       },

                       sucess: function() {                              
                             alert('teste');

                           }

                   });
               });

1 answer

2


It’s typed wrong, the correct is:

success

you can also use the error, if any problem occurs, it would look more or less like this:

    success: function(){
                alert("teste");
            },
    error: function(){
                alert("erro");  
            }

Browser other questions tagged

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