[eluser]mattpointblank[/eluser]
Hi all.
My site has a shop module which features an ajax shopping cart. In case the user has javascript disabled, the shop works without ajax too.
To do this, my addtobasket() function has some code to check whether a 'JS' variable is defined. This variable is only passed when the user adds an item using javascript, so I can refresh the page if the user isn't using javascript.
I enabled gzip compression a few days ago then noticed ajax wasn't working anymore for the shop. I finally fixed this by disabling the gzip compression, but I thought people might need to know.
In terms of code, here's what my controller was doing:
Code:
function addtobasket($id = NULL)
{
$this->load->model('Shop_model');
$item_data = array(
'ProductID' => $this->input->post('id'),
'ClientIP' => $this->input->ip_address(),
'DateAdded' => date("Y-m-d H:i:s")
);
$this->Shop_model->addToBasket($item_data);
if(!$this->input->post('JS')) {
redirect('/shop');
} else {
$output = $this->getHTMLBasket($uuid);
echo json_encode(array('code' => "1", 'html' => $output));
}
}
When I ran this code, I got redirected each time, even thought the JS parameter was being passed (Firebug confirmed this for me).
Does anyone know why gzipping my content would affect posted ajax variables like this?