• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ajax display div

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 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; ?>

//Controller View setup
public function ajax_edit($id)
$data = $this->Product_model->get_by_id($id);
$this->load->view('prodview', $data); 
echo json_encode($data);


// Jquery Ajax setup 

function prev_product(id){
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');

Your missing the # for one and you also need the full url.

Site_url includes index.php

url : "<?php echo site_url('products/ajax_edit/');?>"+id,

$(#showthis).load("<?php echo site_url('index.php/products/method');?>", data, true); // tried to load view here but no joy

I  usually add this to my html it makes it easier to get the url in jQuery

<html lang="en">


   <!-- Pass base_url() and site_url() to JavaScript -->
   <!-- url: siteUrl+id, baseUrl+'method/'+id, etc;
       var baseUrl = "<?php echo base_url(); ?>";
       var siteUrl = "<?php echo site_url(); ?>";

If you want to use and show index.php then use baseUrl.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

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);

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.