My function called register does not send the data to the controller even though everything is fine, it only returns error, but how is it possible? if in the condition I say, if the field is empty I return error, but it is not empty I should return the message "success", What am I doing wrong?
$(function () {
$("#btn-registrar").on('click', function(event) {
event.preventDefault();
var _form = $("#form-Registrar");
if (_form.find('#nombres').val()==='') {
return false;
};
$.ajax({
url: baseURL +'usuario/registrar',
type: 'POST',
dataType: 'json',
data: _form.serializeArray(),
}) .done(function(response) {
if (Boolean(response.status)===true) {
//loadURL(baseURL+'marcas/list_marcas');
alert("exito");
}else{
alert(response.message);
}
}).fail(function(response) {
console.log("error",response);
})
});
});
Here the controller:
<?php class Usuario extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('Model_Usuario');
}
public function index(){
$data['contenido']="usuario/index";
//$data['contenido']="usuario/index";//enviar a plantilla la vista
$data['selPerfil']=$this->Model_Usuario->selPerfil();
$this->load->view("plantilla",$data);//cargamos la plantilla
}
public function registrar(){
echo "sadsa";
}
}?>
Here the views:
<h1>FORMULARIO DE REGISTRO</h1>
<form id="form-Registrar">
<div class="form-group">
<label for="exampleInputPassword1">Nombres</label>
<input type="text" class="form-control" id="nombres" placeholder="Nombres">
</div>
<button id="btn-registrar" type="submit" name="werwrw" class="btn btn-default">Registrar</button>
</form>