jQuery的AJAX请求返回禁止(403)在CakePHP项目 [英] Jquery Ajax Request return forbidden (403) in cakePHP project

查看:247
本文介绍了jQuery的AJAX请求返回禁止(403)在CakePHP项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑2

我还需要帮助,因为错误仍然是不固定的。 下面我添加了一个链接到什么.ajaxError()则会引发截图:

I still need help, as the error still isn't fixed. Below I have added a link to a screenshot of what .ajaxError() does throw:

http://i.imgur.com/RkcgNtG.jpg

另外一个想到的是服务器的设置。是否有任何suphp或机会mpm_itk模块的原因这个错误?

Another thought was the server setting. Is there any chance that suphp or the mpm_itk module are the cause for this bug?

修改

我想通了一些事情。我的Ajax的通话应该更新从输入和textarea的一些数据。我测试了一些,只见那403只有当我textarea的价值或我输入的值有一个以上的空白......所以,这 - 是 - 一 - 测试和thatisatest做工精细发生,而是这是一个文本'返回403

I have figured out something. My Ajax-Call should update some data from an input and a textarea. I tested some more and saw that the 403 only occurs when the value of my textarea or the value of my input has more than one whitespace ... So 'that-is-a-test' and 'thatisatest' work fine, but 'that is a text' returns a 403.

我也想补充的是,Ajax的通话与一个get-方法完成。

I also want to add that the Ajax-Call is done with a get-method.

我有一个问题,工作在我的CakePHP的项目。 首先我必须说,我是新来CakePHP的,而我的工作,这不是开发由我最初的一个项目。

I've got a problem working on my cakePHP project. First of all I have to say that I am new to cakePHP and that I work on a project that was not developed by me initially.

我已经建立了这个项目在我的本地(Windows 8中使用XAMPP),一切工作正常。

I have set up this project on my localhost (Windows 8 with xampp) and everything works fine.

在下一步我编辑的引导配置文件,纠正了数据库信息,并上传所有文件到我的服务器。

In a next step I edited the Bootstrap-Configuration file, corrected the database information and uploaded all files to my server.

现在的一切仍然只是jQuery的AjaxCalls的工作。跟踪这个错误的根源,我看到服务器返回403状态code。

Now everything still works, except for the jQuery AjaxCalls. Tracing the root of this error I saw that the server returns an 403 Status Code.

现在我搜索了可能的原因。第一个方面,我发现是设置安全级别,从高到中等。但正如我的2.x的项目没有此设置了,我需要另一种解决方案。

Now I searched for possible reasons. First aspect I found was to set the security-level from high to medium. But as my 2.x project does not have this setting anymore, I need another solution.

下一步是要检查服务器设置。但两者的的phpinfo,我的本地版本并且其中错误发生的服务器,似乎是几乎相同的。 只有PHP版本5.3的服务器上,并使用FastCGI的是不同的。 但作为CakePHP的不需要超过5.2不能是原因。

Next step was to check the server settings. But the phpinfo of both, my local version and the server where the error takes place, seem to be nearly the same. Only the PHP version of 5.3 on the server and the use of FastCGi are different. But as cakePHP do not need more than 5.2 that cannot be the reason.

所以,现在我不知道该怎么寻找。我认为它是一个设置,因为它工作正常在我的本地,另一台服务器上运行良好,但未能在新服务器上。 任何想法我可以检查?由于我不是服务器技术方面的专家,如果你回答尽可能详细地将是巨大的。

So now I have no idea what to search for. I think it has to be one setting because it works fine on my localhost, worked fine on another server but fails on the new server. Any ideas I could check? As I am not an expert of server technologies it would be great if you answer as detailed as possible.

感谢和问候

推荐答案

现在我已经改变了我的jQuery Ajax的电话,看起来像下面的

I have now changed my jQuery Ajax-Call that looks like following

    $.ajax({
        url: '/metas/saveMetas',
        data: {
            "model": model,
            "f_key": f_key,
            "pagetitle": pagetitle,
            "keywords": keywords,
            "description": description,
            "niceurl": niceurl
        },
        dataType: 'json',
        complete: function(){
            return false;
        },
        success: function(result) {
            if(typeof result =='object') {
                $('#modal-spinner-seo-update').hide('slow');
                jQuery.each(result, function(field, message) {
                    $('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
                });
            } else {
                $('#modal-spinner-seo-update').hide('slow', function() {
                    $("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
                });
            }
            return false;
        }
    });

成一个简单的JavaScript xmlHtt prequest如下

into a simple JavaScript xmlHttpRequest as following

    xhr = new XMLHttpRequest();
    xhr.onreadystatechange=function()
    {
        if (xhr.readyState==4 && xhr.status==200)
        {
            console.log(xhr.responseText);
            if(typeof xhr.responseText =='object') {
                $('#modal-spinner-seo-update').hide('slow');
                jQuery.each(result, function(field, message) {
                    $('#seo-'+field).next('div.error-message').html(message).fadeIn('fast');
                });
            } else {
                $('#modal-spinner-seo-update').hide('slow', function() {
                    $("#seo-widget-message-success").fadeIn('slow').delay(2000).fadeOut('slow');
                });
            }
            return false;
        }
    };
    xhr.open('GET','/metas/saveMetas?model='+model+'&f_key='+f_key+'&pagetitle='+pagetitle+'&keywords='+keywords+'&description='+description+'&niceurl='+niceurl, true );
    xhr.send();

和现在一切似乎很好地工作。但我还是不明白为什么。任何人都可以解释我做错了什么?

and now everything seems to work fine. But I still do not understand why. Can anyone explain what I did wrong?

这篇关于jQuery的AJAX请求返回禁止(403)在CakePHP项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆