ajax display div - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: ajax display div (/showthread.php?tid=71524) |
ajax display div - TekTime - 08-24-2018 I need to display an ajax view in a div named showthis, I am able to see the generated view within the console, but how can I get the view to display within the div "showthis" this is what I have so far. Thanks in-advance for your assistance. // Main view setup foreach($products as $product) : ?> <div class="acc-item-slot"> <?php echo $product->title; ?> <?php echo $product->description; ?> <?php echo $product->sales; ?> <a href="#" onclick="prev_product(<?php echo $product->campaignID;?>)">Preview</a> <?php endforeach; </div> <div id="showthis"> // I would like to load view below here <div id="prodview"> // Example of view prodview.php I would like to load <?php echo $product->title; ?> <?php echo $product->description; ?> <?php echo $product->sales; ?> </div> </div> //Controller View setup public function ajax_edit($id) { $this->load->model('Product_model'); $data = $this->Product_model->get_by_id($id); $this->load->view('prodview', $data); echo json_encode($data); } // Jquery Ajax setup function prev_product(id){ $.ajax({ type : "POST", url : "<?php echo site_url('index.php/products/ajax_edit')?>/"+id, dataType : "JSON", success: function(data){ $(showthis).load('index.php/products/method', data, true); // tried to load view here but no joy }, error: function (jqXHR, textStatus, errorThrown) { alert('Error get data from ajax'); } }); } RE: ajax display div - InsiteFX - 08-25-2018 Your missing the # for one and you also need the full url. Site_url includes index.php Code: url : "<?php echo site_url('products/ajax_edit/');?>"+id, I usually add this to my html it makes it easier to get the url in jQuery Code: <html lang="en"> If you want to use and show index.php then use baseUrl. RE: ajax display div - TekTime - 08-27-2018 Thanks for your response, turns out that I just needed to add ("$data=") My controller view now reads: $data = $this->load->view('prodview',$data, TRUE); $this->output->set_output($data); |