I can not get into the success json function

0

Dai guys .... I'm not able to pass the return of my code to the function success of my ajax via json .... I'm using codeiginiter, php, mysql .... someone you can help me .... it's been almost a week since I'm trying and I do not unpack ...

My controller ....

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
function __construct() {
    parent::__construct();
}
public function index() {
    $dados['tituloPrincipal'] = 'Login';
    $this->load->view('Listar/login', $dados);
}
public function cadastroLogin() {
    $dados['nomeCliente'] = $this->input->post('nomeCliente');
    $dados['telefoneCliente'] = $this->input->post('telefoneCliente');
    $dados['senhaCliente'] = $this->input->post('senhaCliente');
    $dados['emailCliente'] = $this->input->post('emailCliente');
    $this->load->model("mLogin");
    $result = $this->mLogin->cadastrandoLogin($dados);
    $msg['success'] = false;
    if ($result) {
        $msg['success'] = true;
    }
    echo json_encode($msg);
}

}

My Model ....

public function __construct()
{
    parent::__construct();
    $this->load->database();
}
public function cadastrandoLogin($dados = null) {
    if ($dados != null) {            
        $this->db->insert('clientes', $dados);
    }
    try {
        return true;
    } catch (Exception $exc) {
        return false;
    }
}

}

My script .....

$(function () {
$('#adicionarCliente').click(function () {
    var data = $('#cadastroCliente').serialize();
    if ((nomeCliente && emailCliente && telefoneCliente && senhaCliente) != null) {
        $.ajax({
            method: 'POST',
            url: '<?php echo base_url() ?>Login/cadastroLogin',
            data: data, //Dados
            async: false,
            dataType: 'json',
            success: function (response) {
                if (response.success) {
                    alert(response);
                    //ajax_redirect('<?php echo base_url() ?>Login');
                }
                else
                {
                    alert("Lasco");
                }
            },
            error: function () {
                alert('Lascado');
            }
        });
    }
});
});
    
asked by anonymous 29.06.2017 / 03:53

0 answers