I am creating a modal in ajax where it will return the id and list the information in the modal the problem is that the php returns the "whole page" for ajax and gives me no error in the console, I already tried to use firebug
<script>
$(function() {
$(".j_modal").click(function() {
var id_email = $(this).attr('id');
$.ajax({
url: 'Cad_emails',
type: 'POST',
data: "acao=abre_modal&id_email="+id_email,
success: function(dados){
console.log(dados);
}
});
});
});
</script>
<?php
if ($_POST['acao']) {
$j_idemail = $_POST['id_email'];
$resultado = $this->db->get_where('emails', array('i_email' => $j_idemail))->result_array();
echo 'ok';
}
?>
follows the print from the console where it returns the HTML of the page when it should return an array with the data passed in ajax
I'musingcodeigniter
<?phpdefined('BASEPATH')ORexit('Nodirectscriptaccessallowed');classCad_emailsextendsCI_Controller{public$data_up='';publicfunction__construct(){parent::__construct();$this->load->model('emails_model');}publicfunctionindex(){$this->load->helper(array('text','anexos_helper'));$last_email=$this->db->query("SELECT emails.i_email, emails.'status' FROM 'emails' ORDER BY emails.i_email DESC LIMIT 1")->result_array();
$regras = array(
array(
'field' => 'assunto',
'label' => 'Assunto',
'rules' => 'trim|required|max_length[100]|min_length[4]'
),
array(
'field' => 'corpo',
'label' => 'Mensagem',
'rules' => 'trim|required'
),
array(
'field' => 'status',
'label' => 'Status',
'rules' => 'required'
)
);
$this->form_validation->set_rules($regras);
if ($this->form_validation->run()) {
$last_idmail = $last_email[0]['i_email']+1;
$inputs = array(
'i_email' => $last_idmail,
'dt_email' => date('Y-m-d H:i:s'),//2015-05-27 16:43:13
'assunto' => $this->input->post('assunto'),
'corpo' => htmlspecialchars($this->input->post('corpo')),
'status' => $this->input->post('status')
);
$anexos = upload_anexo('anexos', $last_idmail);
if ($anexos['file_name'] != ''){
$data_up = array(
'i_email' => $last_idmail,
'legenda' => NULL,
'arquivo' => $anexos['file_name'],
'status' => 'A'
);
$this->db->insert('anexos', $data_up);
}
$this->db->insert('emails', $inputs);
$this->session->set_flashdata('ok', 'E-mail cadastrado com sucesso!');
redirect(current_url());
}
$data['for_emails'] = $this->emails_model->get_emails();
$data['for_envios'] = $this->emails_model->get_envios();
$this->load->view('cad_emails/emails_plincipal', $data);
}
}
/* End of file Cad_emails.php */
/* Location: .//C/wamp/www/emails_crebas/app/controllers/Cad_emails.php */
The content of the driver is more likely that the problem is not in it, since it has no interaction with ajax that is only in the view.