Jquery Ajax Request return forbidden (403) in cakePHP project

前端 未结 1 1487
挽巷
挽巷 2021-01-24 21:22

EDIT 2

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.i

相关标签:
1条回答
  • 2021-01-24 22:02

    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;
            }
        });
    

    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?

    0 讨论(0)
提交回复
热议问题