我对Ajax Query Codeigniter有错误



我在开发人员控制台中有一个错误:

(index):1 Access to XMLHttpRequest at 'https://www.sigere.site/login/makeLogin?user=admin&pass=123456' from origin 'https://sigere.site' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我正在进行简单的登录和重定向到CodeIgniter中的其他页面那是我的ajax查询

$.ajax({
            url: base_url+'login/makeLogin',
            type: 'GET',
            dataType: 'json',
            data: data,
            beforeSend:function(){
            },
            success:function(r){
                if(r.response==2){
                    window.location.replace(base_url+'Admin');
                }
            },
            error:function(xhr, status, msg){
                console.log(xhr.responseText);
            },
            complete: function () {
            }
        });

我在控制器中的功能是

public function index() { 
        $this->load->view('registro');
    }

尝试允许

header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, OPTIONS"); 

或在HTACCESS文件中添加此。

<FilesMatch ".(eot|ttf|otf|woff)">
    Header set Access-Control-Allow-Origin "*"
</FilesMatch>

相关内容

最新更新