ajax动态输出和判断

ajax动态输出前端内容,这里是基于jq方法。

$.ajax({
  url: goal.url+'springfestival/get-record-data.action?phoneNumber='+self.phone,
  type: 'get',
  dataType: 'json',
  success:function(d){
    var records = d.data.records;
    if(records.length){
      var len = records.length;
      var result = "";
      for(var i =0; i< len; i++) {
        result += '<div class="content clearfix">'
            +'<div class="con_l left">'
            +'<p>'+records[i].prizeName+'</p>';
        if(records[i].prizeMessage){
            result += '<p class="codeNumber">券码:<span>'+records[i].prizeMessage+'</span></p>';
        };
        result+='<p>有效期:2017.12.20</p>'
        +'</div>'
        +'<div class="con_r right">';
        if(records[i].prizeLevel == 1){
          result+='<a href="1.html" style="margin-top:.8rem;">立即领取</a>';
        }else if(records[i].prizeLevel == 2){
          result+='<a href="2.html">立即领取</a>';
        }else if(records[i].prizeLevel == 3){
          result+='<a href="2.html">立即领取</a>';
        }else if(records[i].prizeLevel == 4){
          result+='<a href="2.html">立即领取</a>';
        }else if(records[i].prizeLevel == 5){
          result+='<a href="2.html">立即领取</a>';
        };
        result+='</div></div>';
       }
        $("#PrizeContent").html(result);
       }else{
        $(".getPrize").text("暂无奖品");
      }
    }
  })

posted on 2017-10-16 10:36  沉默火山  阅读(488)  评论(0编辑  收藏  举报