首页 > 解决方案 > Ajax livecount 不是逗号格式

问题描述

如何以逗号形式显示我的计数?目前,即使它是千位形式,它也没有做逗号。有什么办法可以让它工作吗?先感谢您。我提供了下面的代码和我当前问题的屏幕截图 + 我的目标。提前感谢您,祝您有美好的一天。

在此处输入图像描述

HTML:

//// I do show my live count by triggering the id="countBalance" from my ajax script

    <h3 id="countBalance"><sup style="font-size: 20px"> Php</sup></h3>

阿贾克斯:

<script>
function liveBalance(){

  $.ajax({          
            url:'<?=site_url('masteragent/liveBalance')?>',
             type: "POST",
            dataType:"json",
            success:function(data){
            $('#countBalance').html(data);
 
            }
      });





}
setInterval(function(){ 
liveBalance() 
},1000);

</script>

控制器:

function liveBalance(){
    
    
    
    $output=$this->masters->live_balance();
    
    echo json_encode($output);
}

模型:

 function live_balance(){
        
        $reqamount= $this->session->userdata('uid');
        
        $this->db->select('balance');
        $this->db->where('maID',$reqamount);
        
        $result = $this->db->get('prefunding_ma')->row();
        
        return $result->balance;
    }

标签: javascriptjqueryajaxcodeigniter

解决方案


亲爱的您的控制器更改

echo json_encode($output);

echo json_encode(number_format($output));

推荐阅读