Php 使用Codeigniter从AJAX返回多个值,并在两个不同区域显示它们
我正在开发一个带有codeigniter的购物车。我正在使用ajax删除购物车项目。 我的问题是我返回了2个不同的ajax请求响应,我得到了完美的结果,但我需要在不同的地方显示2个不同的html响应 Ajax代码Php 使用Codeigniter从AJAX返回多个值,并在两个不同区域显示它们,php,ajax,codeigniter,shopping-cart,Php,Ajax,Codeigniter,Shopping Cart,我正在开发一个带有codeigniter的购物车。我正在使用ajax删除购物车项目。 我的问题是我返回了2个不同的ajax请求响应,我得到了完美的结果,但我需要在不同的地方显示2个不同的html响应 Ajax代码 function remove_cart(itemid) { $.ajax({ type: 'POST', url: '<?php echo site_url("ajax_controller1/remove_car
function remove_cart(itemid)
{
$.ajax({
type: 'POST',
url: '<?php echo site_url("ajax_controller1/remove_cart/'+itemid+'")?>',
data: { id:itemid },
success:function(response){
$("#shoppingcart_container").html(response);
}
});
}
<td><a onclick="remove_cart('<?=$items['rowid'];?>')" class="icon-close" ><span aria-hidden="true" class="icon_close"></span></a></td>
功能删除购物车(itemid)
{
$.ajax({
键入:“POST”,
url:“在控制器中:
public function removeCart()
{
..
$data = array(
'count'=>$this->cart->contents(),//modify this to return count.
'cart'=> $this->view_shoppingcart()//modify this to return the html output.
);
echo json_encode($data);
}
在ajax代码中:
function remove_cart(itemid)
{
$.ajax({
type: 'POST',
url: '<?php echo site_url("ajax_controller1/remove_cart/'+itemid+'")?>',
data: { id:itemid },
success:function(response){
response= JSON.parse(response);
$("#shoppingcart_container").html(response.cart);
$("#count_container").html(response.count);
}
});
}
功能删除购物车(itemid)
{
$.ajax({
键入:“POST”,
url:“我收到错误<代码>解析错误:语法错误,在<代码>中出现意外的“cart”(T_常量\u装箱的字符串),预期“)”,感谢您的响应,但不幸的是它不起作用。当我发出警报<代码>警报(响应'
时,我收到结果,但当<代码>警报(响应.cart)
或警报(响应.count)`它显示未定义我应该使用数据类型:“JSON”
addresponse=JSON.parse(response)
根据editalerting响应,但不是在(response.cart)
function remove_cart(itemid)
{
$.ajax({
type: 'POST',
url: '<?php echo site_url("ajax_controller1/remove_cart/'+itemid+'")?>',
data: { id:itemid },
success:function(response){
response= JSON.parse(response);
$("#shoppingcart_container").html(response.cart);
$("#count_container").html(response.count);
}
});
}