$ajax->submit 不转到控制器
我正在使用 cakephp 和 pippoacl 插件,我根本无法添加新角色。我在插件中修改的是使用ajax进行提交,在我看来是这样的(add.ctp):
<?php echo $ajax->submit(
'submit',
array(
'url' => array('controller' => 'roles', 'action' => 'add'),
'before' => 'beforeSubmitAdd();',
'complete' => 'completeSubmitAdd(request);'
)
);
?>
当第一次加载add.ctp时,我可以从控制器中打印一些东西。但上面的 ajax 提交仅在“之前”和“完成”时执行 JavaScript。我检查了萤火虫,响应是空白的。
在我的控制器上:
function add() {
print_r("start");
if (!empty($this->data)) {
print_r("add new role");
// save new role
}
}
我使用 ajax 提交用户,并且添加新用户没有任何问题。有什么想法我应该检查哪里吗?我已经比较用户和角色代码一周了,我也请朋友查看我的代码,但我们仍然找不到导致此问题的原因。
提前致谢! :D
I am using cakephp and pippoacl plugin and I simply cannot add a new role. What I modify in the plugin is to make the submit using ajax, something like this in my view (add.ctp):
<?php echo $ajax->submit(
'submit',
array(
'url' => array('controller' => 'roles', 'action' => 'add'),
'before' => 'beforeSubmitAdd();',
'complete' => 'completeSubmitAdd(request);'
)
);
?>
When the add.ctp gets loaded for the first time, I can print_r something from the controller. But the ajax submit above only executes the javascript on 'before' and 'complete'. I check on the firebug, the response is blank.
On my controller:
function add() {
print_r("start");
if (!empty($this->data)) {
print_r("add new role");
// save new role
}
}
I use ajax submit for user and I don't have any problem adding new user. Is there any idea where I should check? I have been comparing the user and role code for a week and I have asked a friend to look at my code, too, but we still cannot find what causes this.
Thanks in advance! :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对 Ajax 助手不太熟悉,但我已经很久没有使用它了,以至于我不记得它在做什么:)。
回到问题。
你检查一下Ajax地址中请求的URL是否正确?这应该很简单,但 URL 可能无效。
您是否使用安全组件(甚至只是将其添加到 var $components 变量上)?这可能会导致黑屏,特别是如果您以某种方式修改表单中的字段。尝试将其删除,看看它是否可以正常工作。
最后我会说我将如何使用 jQuery 来做到这一点。
以下代码应该完成这项工作:
这将处理系统表单中的所有提交,但您当然可以修改。
I am not so familiar with the Ajax helper, but I haven't using it from so long that I can't remember what is it doing :).
Back to the problem.
Did you check if the requested URL in the Ajax address is correct? This should work straightforward, but it's possible that the url to be invalid.
Are you using Security component (even just adding it on the var $components variable)?. This could lead to blank screen especially if you modifying the fields in the form somehow. Try to remove it and see if it's working without.
Finally I would say how I would do it with jQuery.
Following code should do the job:
This will handle all submits in the forms of the system, but you can modify of course.