Hello
I'm trying to insert data into my bank with ajax but I'm not getting it, it always returns me the error message
Controller:
public function insert_user_data(){
$this->load->model('crud');
$this->crud->insert_user_data();
}
Model:
public function insert_user(){
$data_insert = array(
'nome' => $this->input->post('nome'),
'email' => $this->input->post('email'),
'telefone' => $this->input->post('telefone'),
'idade' => $this->input->post('idade')
);
$this->db->insert('usuarios', $data_insert);
}
view and jequery:
<script type="text/javascript">
$(document).ready(function(){
$("#formInsert").submit(function(e){
e.preventDefault();
$.ajax({
url: "<?php echo site_url('/welcome/insert_user_data')?>",
type: "POST",
data: $("#formInsert").serialize(),
success: function(){
alert("foi");
},
error: function(){
alert("deu pau");
}
});
});
});
</script>
<form id="formInsert" >
Nome:
<input type="text" name="nome" class="form-control"/>
<br>
E-mail:
<input type="text" name="email" class="form-control"/>
<br>
Telefone:
<input type="text" name="telefone" class="form-control" />
<br>
Idade:
<input type="text" name="idade" class="form-control" />
<br>
<input class="btn btn-default" type="submit" />
</form>