Javascript 在zf2项目中集成ajax脚本
我想用ajax保存复选框更改。但我无法保存任何更改 这是视图:actionacces.phtml 控制器中的此功能:Javascript 在zf2项目中集成ajax脚本,javascript,ajax,zend-framework2,Javascript,Ajax,Zend Framework2,我想用ajax保存复选框更改。但我无法保存任何更改 这是视图:actionacces.phtml 控制器中的此功能: public function modifroleAction() { $request = $this->getRequest(); // echo'<pre>'; print_r($this->getRequest());die; if ($request->isPost()
public function modifroleAction() {
$request = $this->getRequest();
// echo'<pre>'; print_r($this->getRequest());die;
if ($request->isPost()) {
$parametres = $this->params()->fromPost();
$acl = new Acl();
$acl->fk_role_id = $parametres['role_id'];
$acl->fk_action_id = $parametres['action_id'];
$acces = $parametres['acces'];
if ($acces == "false") {
$acl->acces = 0;
} else {
$acl->acces = 1;
}
$this->getAclTable()->saveAcl($acl);
return $this->redirect()->toRoute('acl');
}
}
public function modifyfroleaction(){
$request=$this->getRequest();
//回显“;打印($this->getRequest());死亡;
data: {
"id_role": role_id,
"id_action": action_id,
"acces": acces
},
如果($request->isPost()){
$parametres=$this->params()->fromPost();
$acl=新acl();
$acl->fk_role_id=$Parameters['role_id'];
$acl->fk_action_id=$Parameters['action_id'];
$acces=$parametres['acces'];
如果($acces==“false”){
$acl->acces=0;
}否则{
$acl->acces=1;
}
$this->getAclTable()->saveAcl($acl);
返回$this->redirect()->toRoute('acl');
}
}
您能帮助我吗?您正在尝试通过$parametres['role\u id']和$parametres['action\u id']获取数据,这意味着role\u id和action\u id 但是你在发送- 这意味着id_角色和id_操作
更改您的帖子索引可能会起作用。您是否检查过您的ajax.url:“Detect/Acl/modifrole”?或者您是否正在控制器ModifyLeaction()中获取数据?
public function modifroleAction() {
$request = $this->getRequest();
// echo'<pre>'; print_r($this->getRequest());die;
if ($request->isPost()) {
$parametres = $this->params()->fromPost();
$acl = new Acl();
$acl->fk_role_id = $parametres['role_id'];
$acl->fk_action_id = $parametres['action_id'];
$acces = $parametres['acces'];
if ($acces == "false") {
$acl->acces = 0;
} else {
$acl->acces = 1;
}
$this->getAclTable()->saveAcl($acl);
return $this->redirect()->toRoute('acl');
}
}
data: {
"id_role": role_id,
"id_action": action_id,
"acces": acces
},