zzl001 发表于 2017-12-29 22:31:31

ajax php 点击加载更多

  前端部分:
  js:
  $(function ()
  {
  $('.get_more').click(function ()
  {
  if($(this).text()=='没有更多了'){return false;} //停止加载
  var list_num = $('.list').length;//获取当前总条数
  var amount = 3 ; //每次点击加载条数
  $(this).text('').append("<img src='images/loader.gif'>");
  $.post('more.php',{list_num:list_num,amount:amount},function (result){ if(result=='not_more'){$('.get_more').text('没有更多了');}else{$('.get_more').text('查看更多记录'); $('#record_box').append(result);}})
  })
  })
  html:
  <div>
  <a href="javascript:history.go(-1)"><img src="images/back.png"></a>资金明细
  </div>
  <div>
  <%foreach from=$userInfo_arr key=key item=value%>
  <div>
  <div><%$value.type_ch%><br><%$value.time%></div>
  <div><span><%if $value.type_en=='plus'%>+<%elseif $value.type_en=='reduce'%>-<%/if%><%$value.amount%>元</span></div>
  </div>
  <%/foreach%>
  <%if $userInfo_arr%>
  <div>查看更多记录</div>
  <%else%>
  <div>没有相关记录</div>
  <%/if%>
  </div>
  后端部分:
  php:
  $list_num = $_POST['list_num'];//记录条数
  $amount = $_POST['amount'];      //一次查询多少条

  $sql = 'SELECT * FROM '.$GLOBALS['ecs']->table('app_user_payrecord')."WHERE mobile = '$mobile' ORDER BY>  $userInfo = $GLOBALS['db']->getAll($sql);
  if(empty($userInfo))
  {
  echo 'not_more';
  }else
  {
  for($i=0;$i<count($userInfo);$i++)
  {
  $type_ch = $userInfo[$i]['type_ch'];
  $time = $userInfo[$i]['time'];
  $type_en = $userInfo[$i]['type_en'];
  $amount = $userInfo[$i]['amount'];
  switch ($type_en) {
  case 'reduce':
  $symbol = '-';
  break;
  case 'plus':
  $symbol = '+';
  break;
  }
  echo <<<Eof
  <div>
  <div>{$type_ch}<br>{$time}</div>
  <div><span>{$symbol}{$amount}元</span></div>
  </div>
  Eof;
  };
  }
页: [1]
查看完整版本: ajax php 点击加载更多