I'm building shopping web application. the thing that I want is, when user click Add to cart's button, the quantity order will update instantly on the shopping/product.php page
My Update quantity order's logic is in the "add method" controller page.
public function add()
{
// Set array for send data.
$insert_data = array(
'id' => $this->input->post('id'),
'name' => $this->input->post('name'),
'price' => $this->input->post('price'),
'qty' => 1
);
// This function add items into cart.
$this->cart->insert($insert_data);
// This will show insert data in cart.
$this->load->view('header');
$this->load->view('shopping/cart');
$this->load->view('footer');
}
assume I have 2 "view" page
- shopping/product.php - the product list page. this page will submit the button to controller "add" but I use ajax trick. so it will stay on the same page
- shopping/cart.php this page is in the controller add and this is the page that start session. this page I contain the quantity of order data to Session
In shopping/product.php I write function onclick to button(add to cart) and I add the session from shopping/cart.php in this text.
$(document).ready(function(){
$('.add-to-cart').on('click',function(){
document.getElementById('outside_cart_text').innerHTML =
"Qty type <?php echo $this->session->userdata('qty_type'); ?> amount <?php echo $this->session->userdata('qty_product');?>";
});
});
after I click, it change the original text to "Qty type amount". But session value not appear.
the question is how to make it appear instantly?
additional detail : I use this trick in shopping/product.php page. It work like ajax. so after click I still in the same page (and not reload)
<style>
.hide { position:absolute; top:-1px; left:-1px; width:1px; height:1px; }
</style>
<iframe name="hiddenFrame" class="hide"></iframe>
<form action="receiver.pl" method="post" target="hiddenFrame">
<input name="signed" type="checkbox">
<input value="Save" type="submit">
</form>