简体   繁体   English

CakePHP。 Ajax请求不适用于debug = 0

[英]CakePHP. Ajax request not working with debug = 0

I am at a loss. 我很茫然。 I submit a form via Ajax using 我使用Ajax通过提交表单

submitForm: function(element) {
    $.post(
        webroot + 'users/settings',
        $('#AJAXform').serialize(),
        function() {
            var option = $('#AJAXform').find('select option:selected');
            $j.current.v.updateField(element, option.text());
            $j.current.v.removeForms();
        }
    );
}

Indeed everything works fine... that is, until I set the debug level to 0. 实际上,一切工作正常……也就是说,直到我将调试级别设置为0为止。

Then the Ajax request fails. 然后,Ajax请求失败。 But the strange thing is that via Firebug I can see that I get an error 404 with written 但是奇怪的是,通过Firebug,我看到我收到了一个错误404

Not Found 未找到

Error: The requested address '/users/profile' was not found on this server. 错误:在此服务器上找不到请求的地址'/ users / profile'

The problem is that I'm NOT calling the page /users/profile but rather /users/settings (users/profile is the page on which the form is located). 问题是我没有调用页面/ users / profile,而是调用/ users / settings(用户/配置文件是表单所在的页面)。 And this only happens with the debug level to 0. So I guess it's something related to security. 而且只有在调试级别为0时才会发生。所以我想这与安全性有关。

One may think I'm being blackholed, but the problem is that the Security component is not currently activated; 可能有人以为我被黑了,但是问题是“安全性”组件当前未激活。 moreover the blackhole should send a blank page, and not an error 404 (even less for the wrong page). 此外,黑洞应该发送空白页,而不是错误404(错误页面的错误更少)。

EDIT: I solved it. 编辑:我解决了。 It turned out it was a redirect in the response which was giving an error. 原来,这是响应中的重定向,它给出了一个错误。 When debug = 0, that error would not be shown and a 404 would appear instead. 当debug = 0时,将不会显示该错误,而是会显示404。 Firefox would then guess the 404 message (which was not actually sent) Firefox然后会猜测404消息(实际上并未发送)

I solved it with 我解决了

if ($this->RequestHandler->isAjax()) {
    $this->autoRender = false;
}

I solved it. 我解决了 It turned out it was a redirect in the response which was giving an error. 原来,这是响应中的重定向,它给出了一个错误。 When debug = 0, that error would not be shown and a 404 would appear instead. 当debug = 0时,将不会显示该错误,而是会显示404。 Firefox would then guess the 404 message (which was not actually sent) Firefox然后会猜测404消息(实际上并未发送)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM