-1

I have sent product id with the onchange event to the controller, fetched data from the database with the help of that id.now I want to send back fetched data to that view without reloading view. if I reload the view then previous data disappears from that view.

Moona
  • 1
  • you should use AJAX updates, and return a json response from controller (in a different url than original view) and then inside view use the returned json data to update the view dynamicaly – Nikos M. Jul 09 '19 at 13:36
  • Is it possible without json? – Moona Jul 09 '19 at 13:41
  • Yes, Use `AJAX with HTML response`, In that case you can use same view – Jitendra Yadav Jul 09 '19 at 13:46
  • tell me a query. I have an array=$arr so how can I pass this array to view('orders/create'). without loading create view.because I don't want to lose previous data from create (view). – Moona Jul 09 '19 at 13:55
  • @Moona - Go through this will help to understand AJAX . `https://stackoverflow.com/questions/23911438/how-to-get-data-from-database-using-ajax-in-codeigniter` – Jitendra Yadav Jul 09 '19 at 14:03

1 Answers1

0

I think you did some http-request to controller with variable, that contains id.

In my example let it be

var id = 222;

        $.ajax({
            method:"POST", 
            url:'/index.php/sandbox/s1',
            data:{ id:id }
        }).done(function(a){

            $('#info').html(a);
        }).fail(function(){

            alert("It's an epic fail.");
        });

In your controller, in my case it's sandbox.php:

 public function s1() { 

        $id_from_view = $this->input->post('id');
        // smthing process to get array as result
        $arr = [1, 2, 3];

        return print_r($arr); 
    }

I've tested it on such kind of HTML code:

<div id="info"></div>

And it works. Your turn

Aksen P
  • 4,564
  • 3
  • 14
  • 27