I have the following problem, in a view I get the data of a user through a foreach
and one of them is the code, which through a link, I execute a function that passed the same code as parameter:
<a href="" onclick="cargarID(<?=$fila->Id_usuario?>)"><?=$fila->Id_usuario?></a></td>
The function sends the id
to a method of my controller:
<script type="text/javascript">
function cargarID(id= null){
if(id) {
$.ajax({
url:"http://localhost/sistema/usuario_consulta/getID/"+id,
type:"POST",
dataType: 'json',
success:function(respuesta){
window.location.href = "http://localhost/sistema/usuario_consulta/index";
}
});
}
}
</script>
This is my controller, I do this because I need to send a parameter to a query that I have in the model.
function index()
{
$this->load->view('guest/section');
$datos['arrPerfil'] = $this->model_usuario->consulta();
$this->load->view('user/usuario_view', $datos);
}
public function getID($id)
{
if($id) {
$data = $this->model_usuario->consulta($id);
echo json_encode($data);
}
}