Welcome Guest, Not a member yet? Register   Sign In
ajax display div
#1

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');
}
});
}
Reply


Messages In This Thread
ajax display div - by TekTime - 08-24-2018, 09:53 AM
RE: ajax display div - by InsiteFX - 08-25-2018, 03:56 AM
RE: ajax display div - by TekTime - 08-27-2018, 04:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB