javascript - 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;
}
解决方案
亲爱的您的控制器更改
echo json_encode($output);
至
echo json_encode(number_format($output));
推荐阅读
- javascript - 未找到 Enzyme React 按钮组件
- css - 在组件之间切换时,ng-deep 不起作用?
- android - 尝试使用 Delphi 10.4.2 构建 Android 64 位应用程序时出现不兼容的目标链接器错误
- sql - 当内容有 HTML 标签时,如何进行全文搜索?
- c++ - 创建一个列表以根据用户输入在 C++ 中动态分配对象
- python - 访问按钮列表中的多个项目时可以使用拼接吗?
- python - sqlalchemy 中缺少 zxJDBC 连接器(使用 DB2)
- r - 并行嵌套的 foreach 循环
- rest - Sabre 无法使用“重新验证行程”REST API
- php - fetchAll(PDO::FETCH_OBJ) 作为数组返回