ajax请求数据,后台提供数据返回json, 前台js拼html,回填
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
ajax请求
/*全民看盘*/
$('#qmkp').click(function () {
if($("#qmkps tr").length>0){
}else{
var Ajaxurl = "<?php echo site_url('bactive/qmkp'); ?>";
$.ajax({
url: Ajaxurl,
dataType: "jsonp",
data: {},
success: function (data) {
//alert(data);
var HtmlTr = '';
var STATIC_url = "<?php echo STATIC_File_url;?>";
var topL = 1;
var picDefault = "<?php echo $this->config->item('avatarurl_defult');?>";
//alert(picDefault);
var score_level = '';
if(data.Status && data.Data){
$.each(data.Data,function(key,val){
var heigher_type = val.heigher_type;
var stock_rank = val.stock_rank;
var stock_score = val.stock_score;
var stock_win_rate = val.stock_win_rate;
var nickname = val.nickname;
var avatarurl = val.avatarurl;
var picUrl = val.picUrl;
var picDi = val.picDi;
var uidList = val.uidList;
if(heigher_type == 1 || heigher_type ==2){
score_level = "<em class=\"Headvip\"><img src="+STATIC_url+"images/big_v.png"+"></em>";
}
if(topL<=9){
Url = "\'niuNum niuNum"+topL+"\'";
HtmlTr = HtmlTr+"<tr>"+
"<td class=\"tabLeft\" width=\"55\"><span class="+Url+"></span></td>";
}else if(topL <= 19) {
var cl1 = topL%10;
if(cl1 == 0){
var topl1 = 1;
var topl2 = 10;
}else{
var topl1 = 1;
var topl2 = topL;
}
var Url1 = "\'niuNum smallNum"+topl1+"\'";
var Url2 = "\'niuNum niuNum"+topl2+"\'";
HtmlTr = HtmlTr + "<tr>" +
"<td class=\"tabLeft\" width=\"55\"><span class="+Url1+"></span><span class="+Url2+"></span></td>";
}else{
topl1 = 2;
topl2 = 10;
Url1 = "\'niuNum smallNum"+topl1+"\'";
Url2 = "\'niuNum niuNum"+topl2+"\'";
HtmlTr = HtmlTr + "<tr>" +
"<td class=\"tabLeft\" width=\"55\"><span class="+Url1+"></span><span class="+Url2+"></span></td>";
}
HtmlTr = HtmlTr +'<td width="147"><div class=\"infro\" clstag=\"app | keycount | grzx | zck\" οnclick="Niugu_quiz_s('+uidList+')">'+score_level+'<img class="headBg" src="'+picDi+'" /><img class="ykHead" src="'+avatarurl+'" οnerrοr="this.src=\''+picDefault+'\'" /><span class="yhname">'+nickname+'</span></div></td>'+
'<td width="123"><div class="honor"><img src="'+picUrl+'"><span class="ry">'+stock_rank+'</span></div></td>'+
'<td width="102"><span class="red dpj">'+stock_rank+'</span></td>'+
'<td width="72"><span>'+stock_score+'</span></td>'+
'<td class="tabRight" width="74"><span class="red sl">'+stock_win_rate+'</span></td>'+
'</tr>';
topL = topL + 1;
});
$("#qmkps").html(HtmlTr);
}else{
$("#qmkps").html("<tr><td width=\"12%\"><span class=\"\">暂无数据,请稍后再来。</span></td></tr>");
}
}
});
}
})
控制器
public function qmkp()
{
//$data = 1; //全民看盘
$data['pagesize'] = 20;
$data['page'] = 1;
$nrbqmkpList = $this->market->highestRank($data);
if(isset($nrbqmkpList["Data"]["List"])){
$nrbqmkpList = $nrbqmkpList["Data"]["List"];
foreach ($nrbqmkpList as $key => &$value) {
//大v
$heigher_type = $value["heigher_type"];
$market_v = "";
if($heigher_type == 1 or $heigher_type == 2){
$picV = STATIC_File_url."images/big_v.png"; //圆角处理
$market_v = "<em class=\"Headvip\"><img src=\"$picV\"></em>";
}
$value['heigher_type'] = $heigher_type;
$market_level = $value['market_level'];//大盘荣誉等级图标
$stock_rank = config_item('market_score_name')[$market_level];//荣誉等级名称
$value['stock_rank'] = $stock_rank;
$stock_score = $value['market_score'] ? $value['market_score'] : "--";//猜股总积分
$value['stock_score'] = $stock_score;
$stock_win_rate = $value['market_win_rate']*100 ? $value['market_win_rate']*100 . "%" : "--";//大盘胜利率
$value['stock_win_rate'] = $stock_win_rate;
$nickname = isset($value["userinfo"]["nickname"])?mb_strcut($value["userinfo"]["nickname"],0,12,'utf-8'):"";//用户名
$value['nickname'] = $nickname;
$avatarurl = isset($value["userinfo"]['avatarurl'])?$value["userinfo"]['avatarurl']:"";//头像
$value['avatarurl'] = $avatarurl;
$picUrl = STATIC_File_url."images/taogu".$market_level.".png";
$value['picUrl'] = $picUrl;
$picDi = STATIC_File_url."images/smallheadBg.png";
$value['picDi'] = $picDi;
$uidList = $value["userinfo"]['uid'];
$value['picDefault'] = $this->config->item('avatarurl_defult');
$value['uidList'] = $uidList;
}
$this->returns(1,0,'数据获取成功',$nrbqmkpList);
}else{
$this->returns(0,0,'暂无数据');
}
}
封闭返回json方法
/**
* 接口返回值
* Json格式数据
*/
public function returns($status,$code,$msg = '',$data = NULL,$callback = NULL){
// 将时间递归转换为北京标准时间
if(empty($msg)){
// $msg = $this->lang->line(''.$code);
//var_dump($msg);echo "<hr>";
}
if(empty($callback)){
if($data === NULL){
if (empty($this->callback)) {
echo json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg));
} else{
echo $this->callback.'('.json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg)) . ')';
}
}else{
if (empty($this->callback)) {
echo json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg,'Data' =>$data));
} else{
echo $this->callback.'('.json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg,'Data' =>$data)).')';
}
}
}else{
if($data === NULL){
echo $callback.'('.json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg)).')';
}else{
echo $callback.'('.json_encode(array('Status' => $status,'ErrorCode' => $code,'Msg' => $msg,'Data' =>$data)).')';
}
}
exit();
}
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:2 个月前 )
960b763e
5 个月前
8c391e04
8 个月前
更多推荐
已为社区贡献5条内容
所有评论(0)