Sucess Ajax does not work with Controller Codeigniter

0

Good afternoon, I'm a beginner in development.

I have a form that I do not want the page not to be reloaded when the user submits the form. I am using Ajax, I have been able to perform the inclusion in the database using codeigniter + ajax, but the ajax success statement is not being invoked, I would like to know how to invoke it,

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');

                           }

                   });
               });
    
asked by anonymous 02.04.2016 / 21:05

1 answer

2

It is typed the wrong way, the correct one is:

success

You can also use the error, if there is a problem, it would look something like this:

    success: function(){
                alert("teste");
            },
    error: function(){
                alert("erro");  
            }
    
18.04.2016 / 16:15