AJAX 전문가가 AJAX의 내 웹 사이트에서 업데이트 카트 기능을 구축하는 데 도움이되는 데 도움이 필요합니다.Ajax로 카트를 업데이트하려면 어떻게해야합니까?
그러니까 기본적으로, 나는 때 한 input_dropdown 내 제품 중 하나를 수정하면된다 싶은 것이 나의 'update_cart'기능은보기 자동 호출되고 내 가격은 내 입력
편집뿐만 아니라 업데이트 : 내가 Matei
에 일부 진전 덕분에 만든 이후 내 질문을 다시 여기 내보기는 다음과 같습니다
<?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 루프에 있지만 내가 여기, 그것은 문제가되지 않는다고 생각합니다.
$(".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));
}
우리는, 그래서 어떤 업데이 트를 볼 수
는 다음 나는 Matei AJAX 기능을 설정했습니다. 누군가 내가 그 AJAX 기능을 설정하는 방법을 알아 내면 큰 도움이 될 것입니다.
나는 당신이 여기에 너무 많은 질문을하고 있다고 생각합니다. 당신의 질문을 리팩터링 (좋은 수업처럼)하는 것은 하나의 중심적인 목적을 가지고 있습니다. – SomeKittens
yeqh 네 말이 맞아, 그 주제를 약간 썼다 –