我遇到了ajax请求的问题。该功能是增加/减少购物车中的商品。当增量事件触发时,post数组在打印时变为空。
Firebug显示在发布请求中发送的参数,但在控制器中没有任何内容到达。
实施的解决方案有点邋but,但这是必须的。 jquery是document.ready签名之外的非匿名方法,很可能是该问题的一个贡献者。
这就是我的......
的jQuery
function increment_item($ciid){
$("#processing").fadeIn("fast");
$.ajax({
url: "<?=BASE_URL?>landing/inc_cart_item",
type: "post",
dataType: "json",
data: {id:$ciid,},
success: function(data){
$("#processing").fadeOut("fast");
if(data.error) {
alert(data.error);
} else {
// parent.$('#line1').text(data.line1);
//parent.$('#line2').text(data.line2);
//parent.$('#address-dialog').dialog('close');
alert(data.line1);
}
}
});
//return false;
};
视图中的触发器......
<a href="#" onClick="increment_item(<?=$item['cart_item_id']?>)" class="qty-inc-button" >More</a>
控制器方法......
function inc_cart_item(){
$return_val = $this->cart_model->increment_cart_item($this->session->userdata('cart_id'),$this->input->post('id'));
}
编辑添加生成源......
表格数据
</thead>
<tbody id="item_2823">
<tr>
<td>
<img src="http://localhost/cdn/images/112/7/thumb_lemberger2010.jpg">
<p style="color: #666;">Bader</p>
<p style="font-size: 16px;">Stettener Lindhälder Lemberger</p>
<a href="#" onclick="remove_item(2823)" id="remove-item-button" class="remove-item-button">Remove this item</a>
</td>
<td class="align-td-center">
8.20€ </td>
<td class="align-td-center">
<a href="#" onclick="increment_item(2823)" id="qty-inc-button" class="qty-inc-button">More</a>
1 <a href="#" onclick="decrement_item(2823)" id="qty-dec-button" class="qty-dec-button">Less</a>
<input id="item_id" class="item_id" value="2823" type="hidden">
</td>
<td class="align-td-center">
<span id="value-shipping-2823">8.20€</span>
</td>
</tr>
</tbody>
<tbody id="item_2824">
<tr>
<td>
<img src="http://localhost/***/cdn/images/112/5/thumb_kerfttropfle2010.jpg">
<p style="color: #666;">Bader</p>
<p style="font-size: 16px;">Kerftströpfle</p>
<a href="#" onclick="remove_item(2824)" id="remove-item-button" class="remove-item-button">Remove this item</a>
</td>
<td class="align-td-center">
5.10€ </td>
<td class="align-td-center">
<a href="#" onclick="increment_item(2824)" id="qty-inc-button" class="qty-inc-button">More</a>
1 <a href="#" onclick="decrement_item(2824)" id="qty-dec-button" class="qty-dec-button">Less</a>
<input id="item_id" class="item_id" value="2824" type="hidden">
</td>
<td class="align-td-center">
<span id="value-shipping-2824">5.10€</span>
</td>
</tr>
</tbody>
生成的jquery
function increment_item($ciid){
$("#processing").fadeIn("fast");
$.ajax({
url: "http://localhost/***/***/landing/inc_cart_item",
type: "POST",
dataType: "json",
data: {id:$ciid},
success: function(data){
$("#processing").fadeOut("fast");
if(data.error) {
alert(data.error);
} else {
// parent.$('#line1').text(data.line1);
//parent.$('#line2').text(data.line2);
//parent.$('#address-dialog').dialog('close');
alert(data.line1);
}
}
});
};
我试图在这里使用的jQuery函数再次出现在$(document).ready(function(){code block中的所有其他生成的jQuery之外,我不知道这可能是原因。
我现在已经和它搏斗了一段时间,感谢所有的帮助。
由于
答案 0 :(得分:0)
您确定数据是否正确发布?你的数据json里面有一个逗号。
你也可以尝试:
data: JSON.stringify({id:$ciid})