当类型为 POST 时 cakephp Ajax 表单不起作用

发布于 2024-11-07 02:36:18 字数 1018 浏览 1 评论 0原文

我使用 cakephp 1.1 开发了一个网站,它有很多 ajax 元素,可以同时更新多个元素,而且它们工作得很好。现在,我正在迁移到 cakephp 1.3,但我没有这么好的体验。

感谢这个博客 我能够更新多个 div,但很快我又陷入困境。

我当前的问题是 ajax 表单无法完成对 url '/logs/logIn' ('/controller/action') 的请求。

提交表单后,Firebug 向我显示错误:“POST http://localhost/logs/logIn 404 not found ”,请求在原型的 request() 函数中被中断,第 1530 行:

this.transport.send(this.body);

当我直接在浏览器中写入 url 时,该网站似乎按照我的预期工作。当我将表单类型从“POST”更改为“GET”时,ajax 请求完成,响应是我期望的,但我确实需要使用“POST”来完成。

我读过很多讨论类似问题的论坛,但没有任何建议可以帮助我解决问题:

  • 我检查了我的 hhtp.conf 和 .htaccess 文件,根据安装说明它们似乎没问题(但我我不确定)。
  • 我请求的操作不使用任何视图(事实上,“GET”和直接 url 请求功能不需要 log_in.ctp 视图文件),并且当我尝试“POST”ajax 请求时,我已经创建了相应的视图,但还是不行。

我正在使用最新版本的 scriptaculous 和 protoype.js (1.7),我在 ubuntu 上使用 Firefox 3.6.17。

非常感谢您提供任何技巧、提示、建议或任何您可以帮助我的事情。

I developed a site using cakephp 1.1, It has a lot of ajax elements tu update multiple elements simultaneously and they worked pretty well. Now, I am migrating to cakephp 1.3, but I am not having such a great experience.

Thanks to this blog I was able to get multiple divs updated, but soon I got stuck again.

My current problem is with an ajax form which does not complete the request to the url '/logs/logIn' ('/controller/action').

After submiting the form, Firebug shows me an error: "POST http://localhost/logs/logIn 404 not found", the request is interrupted in the function request() of prototype, line 1530:

this.transport.send(this.body);

When I write the url directly in the browser, the site seems to work as I would expect. And when I change the type of the form from 'POST' to 'GET' the ajax request is completed and the response is the one I expected, but I DO NEED to do it with 'POST'.

I have read a lot of forums in which similar issues are discussed, but no suggestion has help me to solve the problem:

  • I have checked my hhtp.conf and .htaccess files, they seem to be fine according to the installation instructions (but I am not sure).
  • The action I am requesting does not use any view (in fact, 'GET' and direct url requets function whit no need of the log_in.ctp view file), and I have created the respective view when I try the 'POST' ajax request, but It still does not work.

I am using the latest version of scriptaculous and protoype.js (1.7), I am working with Firefox 3.6.17 on ubuntu.

Many thaks in advance for any trick, tip, advice or whatever you can do to help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2024-11-14 02:36:18

我终于解决了问题。它与 cake 的安全组件有关。

我所做的只是将 $validatePost 变量设置为 false。

我知道帖子验证适用于第 3 方帖子,但似乎 cake 确实对 enery post 请求进行了验证,即使是源自主应用程序的请求。

I finally got the problem fixed. It had to do with cake's Security component.

All I did was to set the $validatePost variable to false.

I had understood the post valiation was applied to 3rd party posts, but It seems cake does do the validation for enery post request, even the ones originated in the principal app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文