为了账号安全,请及时绑定邮箱和手机立即绑定

ajax怎么不能赋值到前台?

ajax怎么不能赋值到前台?

错过了年华 2017-10-27 03:32:58
 <div class="pay">
                <div class="pay-opt"> <a href="home2.html"><span class="am-icon-home am-icon-fw">首页</span></a> <a><span class="am-icon-heart am-icon-fw">收藏</span></a> </div>
                <li>
                    <div class="clearfix tb-btn tb-btn-buy theme-login"> <a id="LikBuy" title="点此按钮到下一步确认购买信息" href="#">立即购买</a> </div>
                </li>
                <li>
                    <div class="clearfix tb-btn tb-btn-basket theme-login"> <a id="LikBasket" title="加入购物车" href="javascript:addCart({$rst[0]['g_id']})" onClick="showSum()"><i></i>加入购物车</a> </div>
                </li>
            </div>
        </div>
        <div class="clear"></div>
    </div>
   {literal} <script type="text/javascript">
         
          function showSum(){
              var url = "countShopcartid.php";
              
              
             var data = {"not":""};
              var success= function(response){
                  if(response.errno == 0){
                    var sum = response.sum;  
                  $("#LikBuy").html("sum");
                  }else
                  {
                       alert('获取购物车商品数量失败');
                  }
              }
              $.post(url,data,success,"json");
          }
    </script>{/literal}
countShopcartid.php
<?php

require_once('include.php');
//1.接受参数并处理

$user_id = $_SESSION["id"];
//2.计算数量
$sql = "select count(*) from shopcar where  user_id='{$user_id}'";
$row = $admindb->ExecSQL($sql,$conn);
var_dump($row);
//3.返回处理结果
if($row){
	$response = array(
		'errno' =>0,
		'errmsg' =>'success',
		'data' => true,
		'sum' => $row[0]["count(*)"],
	);
}
else{
	$response = array(
		'errno' =>-1,
		'errmsg' =>'fail',
		'data' => false,
		'sum' => $row[0]["count(*)"],
	);
}
echo json_encode($response);
?>

F12看到有值      {"errno":0,"errmsg":"success","data":true,"sum":"4"}  

为什么sum没赋值到  #LikBuy的a标签里,还是我哪里写错了?

查看完整描述

2 回答

?
习惯受伤

TA贡献949条经验 获得超1232个赞

$("#LikBuy").html("sum");
这里改成
$("#LikBuy").html(sum);
看到了吗?

查看完整回答
1 反对 回复 2017-10-27

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信