Welcome Guest, Not a member yet? Register   Sign In
send data to other view via ajax
#1

[eluser]tnathos[/eluser]
hi, i have a dude or problem.. xd..

in my app i send one parameter via ajax using js, whit this parameter i make a select and return the data, whit this data i pass to other view.. the view for show results.

But i have a problem, when i get the data in the controller i send the array to the results view whit $this->load.... but not redirect.. i suppose what the problem its the call ajax, but how i can resolve this?

ajax.

Code:
function buscar_categoria(categoria)
{
    $.ajax({
           type: "POST",
           url: "<?=base_url()?>busqueda/get_categorias/",
           cache: false,
           data: "categoria="+categoria,
           success: function(msg){
        }    
            
    });        
}

controller.

Code:
function get_categorias()
    {    
        $this->load->model('modelbusqueda','get_data');
        $data['resultado']= $this->get_data->get_categorias();
        $this->load->view('/home/busqueda', $data);
    }
#2

[eluser]saidai jagan[/eluser]
U shd Do like this
Code:
function get_categorias()
{    
   $this->load->model('modelbusqueda','get_data');
   $data['resultado']= $this->get_data->get_categorias();
   $view_name = $this->load->view('/home/busqueda', $data,true); // sending the output
   echo json_encode($view_name);
}

// Js
function buscar_categoria(categoria)
{
    $.ajax({
           type: "POST",
           url: "<?=base_url()?>busqueda/get_categorias/",
           cache: false,
           data: "categoria="+categoria,
           success: function(msg){
           $('#div_to_be_displayed').html(msg); // Displays the content
        }    
            
    });        
}




Theme © iAndrew 2016 - Forum software by © MyBB