这是我的代码
function add() {
if(!empty($this->data)) {
if($this->Post->save($this->data)) {
if($this->RequestHandler->isAjax()){ //isAjax method is deprecated.
//Handle Ajax
$this->render('notif','ajax');
} else {
$this->Session->setFlash('Add successfully');
$this->redirect(array('action'=>'index'));
}
}
else {
$this->Session->setFlash('Add failded please try again');
}
}
}
在这里我读到该方法已被弃用 http://book.cakephp.org/2.0/en/appendices/2-0-migration-guide.html?highlight=isajax
如何解决这个问题?
最佳答案
它说 CakeRequest 现在负责这个。您可以在这里找到适当的段落:http://book.cakephp.org/2.0/en/controllers/request-response.html#inspecting-the-request
function add() {
if(!empty($this->request->data)) {
if($this->Post->save($this->request->data)) {
if($this->request->is('ajax')){
//Handle Ajax
$this->render('notif','ajax');
} else {
$this->Session->setFlash('Add successfully');
$this->redirect(array('action'=>'index'));
}
}
else {
$this->Session->setFlash('Add failded please try again');
}
}
}
关于jquery - isAjax() 是 CakePHP 2.0 上已弃用的方法。什么方法可以替代那个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7939320/