我有一个Ajax生成的cakephp 2.0分页记录。但每次我尝试单击 Next 转到下一页时,都会出现缺少链接错误。
如果在没有ajax的情况下生成记录,则效果很好。
AppController的
class AppController extends Controller {
public $helpers = array('Session');
public $components = array(
'Session','RequestHandler', 'Email','Image','Cookie',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'users',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'compass',
'action' => 'index',
'home'
),
'authError' => 'Did you really think you are allowed to see that?',
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish',
'fields' => array('username' => 'email')
)
)
),
);
控制器
public function filterPrice(){
$this->autoRender = false;
$this->layout="ajax";
$this->request->onlyAllow('ajax'); //can't be accessed via http/https
if ($this->Session->read('conditions.fess')) {
$this->Session->delete('conditions.fees');
}
if ($_REQUEST['val'] != 'any') {
$this->Session->write('conditions.fees', $_REQUEST['val'] );
}else{
$this->Session->delete('conditions.fees');
}
$queryConditions = $this->intialiseconditions();
// echo debug($queryConditions);
$this->Paginator->settings = array(
'conditions' => $queryConditions + array('School.level'=> $_REQUEST['level']),
'limit'=>20, 'order' => array('User.membership'=>'asc','School.name'=>'asc'));
$schools = $this->Paginator->paginate('School');
$this->set(compact('schools'));
$this->render('filtered','ajax');
}
我的观点filtered.ctp
<header class="showing">
<div id="range"> Schools:<b><?php
echo $this->Paginator->counter(array(
'format' => 'range'
));
?>
</b>
</div>
<div id="meet">SCHOOL<?php echo (count($schools) >1)? 'S ':' '?>(<?php echo count($schools); ?>) </div>
<div class="counters">
<?php
echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ' | ', 'first' => 1, 'last' => 1));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>
<div class="clearfloat"></div>
</header>
我的jquery
$('.elementtosort').click(function(e){
$('#ttips').fadeOut('slow');
var key = $(this).attr('key');
var val = $(this).attr('value');
var state = $(this).attr('state');
var level = $('#level_holder').val();
//console.log(val);
if($(this).hasClass('disabled')) {
$(this).removeClass('disabled');
$(this).parent('li').find('ul').fadeOut('slow');
$.ajax({
beforeSend:function (XMLHttpRequest)
{$('#overlaybig').fadeIn();
$('#overlaybig7').fadeIn();
},
url: "<?php echo Router::url(array('controller' => 'schools', 'action' => 'setFilters', 'dowhat'=>'remove'), true); ?>",
data:{key:key,value:val, state:state, level:level},
cache: false,
type: 'GET',
dataType: 'Html',
success: function (data, textStatus) {
$("#overlaybig").fadeOut();
$("#overlaybig7").fadeOut();
$('#right_panel').html(data);
}});
// if($(this).hasClas
}else{
$(this).addClass('disabled');
$(this).parent('li').find('ul').fadeIn('slow');
$.ajax({
beforeSend:function (XMLHttpRequest)
{$('#overlaybig').fadeIn();
$('#overlaybig7').fadeIn();
},
url: "<?php echo Router::url(array('controller' => 'schools', 'action' => 'setFilters', 'dowhat'=>'add'), true); ?>",
data:{key:key,value:val, state:state, level:level},
cache: false,
type: 'GET',
dataType: 'Html',
success: function (data, textStatus) {
$("#overlaybig").fadeOut();
$("#overlaybig7").fadeOut();
$('#right_panel').html(data);
},
})
}
return false;
}