我真的需要一些帮助,从AJAX大师主导overthere,以帮助我在我的网站在AJAX建立我的更新购物车功能。如何使用Ajax更新我的购物车?
所以基本上,我想要做的是,当我修改我的产品之一,在一个input_dropdown什么,我的“update_cart”功能automaticaly打来电话,我的价格更新,以及我的输入
编辑:我重写我的问题,因为我取得了一些进展得益于马太
这是我的观点:
<?php
$options = array(
'0' => '0',
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
);
if($product['quantity']==0){
$value[$product['title']] = set_value('quantity'.$product['title']);
}else{
$value[$product['title']] = $product['quantity'];
}
$data0 = 'class="quantSelect" value="'.$value[$product['title']].'" id="quant'.$product['title'].'"';
echo form_dropdown('quantity'.$product['title'], $options, $value[$product['title']],$data0);
?>
</td>
<td>
<?php echo $product['price'] ?>
</td>
<td id="<?php echo 'price'.$product['title']?>">
$<?php echo $total[$product['title']] ?>
</td>[/code]
嘛,一切都在一个foreach循环,但我想,在这里,也没关系。
然后我试图建立马太AJAX功能:
$(".quantSelect").click(function(){
$.POST("<?php echo base_url().'main/update_cart';?>",
{product_id:$('<?php echo $product['quantity']; ?>').val(),quantity:$('<?php echo 'quantity'.$product['title'] ?>').val()},
function(data){
if(data.success) {
$("<?php echo 'price'.$product['title']?>").val(data.some_returned_value); // update value of an text input or textarea (view more info about jQuery selectors)
$("#totalPriceWithTaxes").html(data.some_other_returned_value); // update value of a paragraph
}
}, 'json');
});
,最后更新车功能:
function update_cart(){
$success = false;
if(!empty($_POST['product_id']) && !empty($_POST['quantity']) && is_numeric($_POST['quantity'])) {
// I get all the information i need here in order to calcul the final price
//We calcul the final price with taxes, shipping and everything.
$data['totalPriceWithTaxes'] = $data['tax'] + $data['totalPrice'] + $data['Shipping']->shipping;
$this->session->set_userdata('totalPriceWithTaxes', $data ['totalPriceWithTaxes']);
$success = true;
$some_returned_value = 69;
$some_other_returned_value = $data['totalPriceWithTaxes']; // the final price
}
echo json_encode(array("success" => $success,
"some_returned_value" => $some_returned_value,
"some_other_returned_value" => $some_other_returned_value));
}
我们在这里,所以我不能看到任何更新。如果有人能帮我弄清楚如何设置AJAX功能,我会深表感谢:)
我想你在这里问的问题太多了。重构你的问题(像一个好的课堂)有一个主要目的。 – SomeKittens 2012-07-23 03:30:57
yeqh你是对的,我重写了这个话题 – 2012-07-24 14:29:01