CI 无刷新分页的问题

ljw910_00 2014-12-22 01:08:02
我想用CI实现无刷新分页,我用方法是这样的,但是发现我想要更新的数据都没有更新
我想在点击下一页时,只表格更新,开始时间输入框、结束时间输入框、下拉菜单都不刷新,以为一刷新填入的数据就没了



下面是我的HTML代码 tpl_basicdata
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title><?php if( isset($title) ) echo $title;?></title>
<script src="<?php echo BASE_URL.'app/views/assets/juery/library/jquery-2.1.3.js' ?>" type="text/javascript"></script>
<script src="<?php echo BASE_URL.'app/views/assets/ajax_page.js' ?>" type="text/javascript"></script>
</head>
<body>
<div>
<div>
<h4>当前位置>单服基本数据</h4>
</div>
<hr />
<div>
<?php echo form_open('admin/SignalDataPage'); ?>
开始时间: <input type="text" name="txtStartTime" value="<?php echo set_value('txtStartTime'); ?>" style="width: 180px" onfocus="WdatePicker()" />
结束时间: <input type="text" name="txtEndTime" value="<?php echo set_value('txtEndTime'); ?>" style="width: 180px" onfocus="WdatePicker()" />
渠道权限范围: <select name="ddlist1" style="width:130px;" value="<?php echo set_value('ddlist1'); ?>">
<option>ALL</option>
<option>DUOWAN</option>
</select>
<input id="BtnSearch" type="submit" value="查询"/>
<input id="BtnExport" type="button" value="导出" onclick="window.location='<?php echo site_url("/admin/SignalDataPage/OnExportBtn");?>'"/>
<?php echo form_close(); ?>
</div>
<hr />
<div>
<table border="0" style="border-color:Gray;" cellspacing="0" cellpadding="0" width="100%">
<tr style=" background-color:#87CEFA; height:28px;width:140px; text-align:center;">
<td>日期</td>
<td>新增用户</td>
<td>日均登录次数</td>
<td>DAU</td>
<td>付费渗透率</td>
<td>启动次数</td>
<td>最高在线</td>
<td>平均在线</td>
<td>充值人数</td>
<td>充值次数</td>
<td>单日收入</td>
<td>ARPU</td>
<td>APPPU</td>
</tr>
<?php if(count($page_data) > 0): ?>
<?php $i = 1;?>
<?php foreach($page_data as $row): ?>
<?php if($i%2 === 0): ?>
<tr style="height:26px;background-color:#B0E2FF;text-align:center;">
<?php else: ?>
<tr style="height:26px;background-color:#F2F2F2;text-align:center;">
<?php endif?>
<?php $i++;?>
<td><?php echo $row['DayDate']; ?></td>
<td><?php echo $row['RegCount']; ?></td>
<td><?php echo $row['AverageRepeatLogin']; ?></td>
<td><?php echo $row['DAU']; ?></td>
<td><?php echo $row['PUR']; ?></td>
<td><?php echo $row['ClientOpenTime']; ?></td>
<td><?php echo $row['DayOnlineTop']; ?></td>
<td><?php echo $row['DayAverageOnlineTop']; ?></td>
<td><?php echo $row['PayUserCount']; ?></td>
<td><?php echo $row['PayTatalCount']; ?></td>
<td><?php echo $row['PayMoneySum']; ?></td>
<td><?php echo $row['ARPU']; ?></td>
<td><?php echo $row['ARPPU']; ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</table>
<br>
<div style="text-align:center;"> <?php echo $links; ?></div>
</div>
</div>
</body>
</html>


下面是ajax_page.js ajax分页代码
function ajax_page(page){
if(page=='' || page==null || page==undefined){
page = '';
}
content = '';
$.ajax({
type:'GET',
url:"SignalDataPage/index/"+page,
async:false,
success:function(data){
content = data;
}
});
$(".tab1_class").html('');

$(".tab1_class").html(content);
return false;
}


下面是Controller里的代码
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class SignalDataPage extends MY_AdminController
{
private $strStartDate;
private $strEndDate;

public function __construct()
{
parent::__construct();
$this->load->model('MY_SignalBasicDataModel');
$this->load->model('MY_UserRetainDataModel');
$this->load->library('TableExport');
$this->load->helper('url');
$this->load->library('pagination');

$this->strStartDate = Date('Y-m-d');
$this->strEndDate = Date('Y-m-d');
}

public function SubMenuSelected($subIndex)
{
$this->session->set_userdata('sub_index', $subIndex);
redirect('admin/SignalDataPage');
}

public function index($page=1)
{
echo $page;
$subMenuIndex = 0;
if( isset($this->session->userdata['sub_index']) )
{
$subMenuIndex = $this->session->userdata['sub_index'];
}

$sDate = $this->input->post('txtStartTime');
$eDate = $this->input->post('txtEndTime');
$selectChannel = 'ALL';
if(isset($_POST["ddlist1"]))
$selectChannel = $_POST["ddlist1"];

$offset=intval($this->uri->segment(4));
echo $offset;
if(CheckEmptyString($sDate) != false && CheckEmptyString($eDate) != false)
{
$this->session->set_userdata('start_date', $sDate);
$this->session->set_userdata('end_date', $eDate);
$this->strStartDate = $sDate;
$this->strEndDate = $eDate;
}
else
{
if( isset($this->session->userdata['start_date']) && isset($this->session->userdata['end_date']) )
{
$this->strStartDate = $this->session->userdata['start_date'];
$this->strEndDate = $this->session->userdata['end_date'];
}
}

$tStartData = strtotime($this->strStartDate);
$tEndData = strtotime($this->strEndDate);

if($this->CheckTime($tStartData, $tEndData) === false)
{
return;
}

$rowCount = $this->GetRowCount($tStartData, $tEndData);

$this->InitPageConfig($rowCount, $subMenuIndex);

if($offset > 0)
{
$tStartData = strtotime($offset.' days', $tStartData);
}
else
{
$tStartData = strtotime($offset.' days', $tStartData);
}

if($offset + MAX_ROW_COUNT < $rowCount)
{
$tEndData = strtotime((MAX_ROW_COUNT - 1).' days', $tStartData);
}

$pageData = array();
if($subMenuIndex === '1')
{
$pageData = $this->MY_SignalBasicDataModel->GetSignalBasicDate($tStartData, $tEndData, $selectChannel);
}
else if($subMenuIndex === '2')
{
$pageData = $this->MY_UserRetainDataModel->GetNewUserRetainData($tStartData, $tEndData, $selectChannel);
}
else if($subMenuIndex === '3')
{
$pageData = $this->MY_UserRetainDataModel->GetActiveUserRetainData($tStartData, $tEndData, $selectChannel);
}

if($pageData === false || empty($pageData))
{
show_404();
}

$this->ShowSignalDataPage($pageData, $subMenuIndex);
}

function GetRowCount($itartData, $iEndData)
{
$rowCount = round(($iEndData-$itartData)/3600/24) + 1;
return $rowCount;
}

function CheckTime($tStartData, $tEndData)
{
if($tStartData > $tEndData || $tStartData > strtotime('today') || $tEndData > strtotime('today'))
{
$this->session->unset_userdata("start_date");
$this->session->unset_userdata("end_date");

echo "<script> {window.alert('日期输入错误');location.href='../admin/SignalDataPage'} </script>";
return false;
}
return true;
}

public function InitPageConfig($rowCount, $subMenuIndex)
{
$cfg['base_url'] = site_url('admin/SignalDataPage/send_message');
$cfg['total_rows'] = $rowCount;
$cfg['per_page'] = MAX_ROW_COUNT;
$cfg['cur_tag_open'] = '<a class="current">';
$cfg['cur_tag_close'] = '</a>';
$cfg['first_link'] = '首页';
$cfg['prev_link'] = '上一页';
$cfg['next_link'] = '下一页';
$cfg['last_link'] = '尾页';
$cfg['uri_segment'] = 4;

$this->pagination->initialize($cfg);
}

public function ShowSignalDataPage($pageData = 0, $subMenuIndex)
{
if($pageData === 0)
{
$data['page_data'] = array();
}
else
{
$data['page_data'] = $pageData;
}

$data['links'] = $this->pagination->create_ajax_links();

if($subMenuIndex === '1')
{
$data['title'] = '单服基本数据';
$this->load->view('service/tpl_basicdata', $data);
}
}

public function OnExportBtn()
{
$sDate = $this->strStartDate;
$eDate = $this->strEndDate;
if( isset($this->session->userdata['start_date']) && isset($this->session->userdata['end_date']) )
{
$sDate = $this->session->userdata['start_date'];
$eDate = $this->session->userdata['end_date'];
}
$tStartData = strtotime($sDate);
$tEndData = strtotime($eDate);

$signalBasicData = $this->MY_SignalBasicDataModel->GetSignalBasicDate($tStartData, $tEndData, 'ALL');
$newUserRetainData = $this->MY_UserRetainDataModel->GetNewUserRetainData($tStartData, $tEndData, 'ALL');
$activeUserRetainData = $this->MY_UserRetainDataModel->GetActiveUserRetainData($tStartData, $tEndData, 'ALL');
if($signalBasicData === false || $newUserRetainData === false || $activeUserRetainData === false ||
empty($signalBasicData) || empty($newUserRetainData) || empty($activeUserRetainData))
{
show_404();
}
$pageData = array(
'SignalBasicData' => $signalBasicData,
'NewUserRetainData' => $newUserRetainData,
'ActiveUserRetainData' => $activeUserRetainData
);
$this->tableexport->ExportExcel($pageData, 'SignalData');
}
}

下面点击下一页时HTTP请求


但是数据表格没有更新,请个位大神帮我看看,我刚搞这个两个星期。
...全文
168 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huhyman 2014-12-23
  • 打赏
  • 举报
回复
1.看到你最后一次贴出来的ajax代码里面加了 dataType:"json",那请注意ajax的返回值也应该是json格式。 2.看到你Controller里面的ShowSignalDataPage方法每次获取到数据之后都是要load一次view,感觉不是很理解。我的做法一般是一开始就load一次view,然后使用ajax调用Controller向mode取数据,Controller取好数据并且拼好表格的html再返回给view,view把表格的html更新l就有数据了,看能否帮到楼主。
ljw910_00 2014-12-22
  • 打赏
  • 举报
回复
引用 4 楼 xuzuning 的回复:
没看到你传递这两个变量 $sDate = $this->input->post('txtStartTime'); $eDate = $this->input->post('txtEndTime');
我改成这样还是不行
function ajax_page(page){
  if(page=='' || page==null || page==undefined){
    page = '';
  }
  
  var mydata = {
		  txtStartTime:$("#txtStartTime").val(),
		  txtEndTime:$("#txtEndTime").val()
  };
  content = '';
  $.ajax({
    type:'POST',
    url:"SignalDataPage/index/"+page,
    data:mydata,
    dataType: "json",
    async:false,
    success:function(data){
      content = data;
    }
  });
  $(".tab1_class").html('');

  $(".tab1_class").html(content);
  return false;
}
xuzuning 2014-12-22
  • 打赏
  • 举报
回复
没看到你传递这两个变量 $sDate = $this->input->post('txtStartTime'); $eDate = $this->input->post('txtEndTime');
ljw910_00 2014-12-22
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
你的提交方式是 get
type:'GET',
url:"SignalDataPage/index/"+page,
而你的接收方式是 post
$sDate = $this->input->post('txtStartTime');

这显然是不行的


我把GET改成了POST 如下
function ajax_page(page){
if(page=='' || page==null || page==undefined){
page = '';
}
content = '';
$.ajax({
type:'POST',
url:"SignalDataPage/index/"+page,
async:false,
success:function(data){
content = data;
}
});
$(".tab1_class").html('');

$(".tab1_class").html(content);
return false;
}


但是~~~


于是我打开里面
显示有错而且 option.data 是未定义的,为什么 会这样
小在在 2014-12-22
  • 打赏
  • 举报
回复
正如版主所言,你确定一下提交和接收方式,再看看有没有其它的问题
xuzuning 2014-12-22
  • 打赏
  • 举报
回复
你的提交方式是 get type:'GET', url:"SignalDataPage/index/"+page, 而你的接收方式是 post $sDate = $this->input->post('txtStartTime'); 这显然是不行的

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧