ajax无法与https一起使用,跨域

时间:2019-05-21 05:21:33

标签: ajax https cross-domain

出现此错误:

 GET https://url 503 (Service Unavailable)
        employee_cost_new#:1 Access to XMLHttpRequest at 'https://url' from origin 'http://localhost' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我正在使用此设置进行ajax调用,它在localhost上运行正常,但在https url上出现错误:

NodeJs_API_Helper.prototype.getAjaxCommonSettings = function(url){
    console.log('Auth', this.getCookie());
    var settings = {
            "async": true,
            "crossDomain": true,
            "headers": { 'Auth': this.getCookie() },
            "method": "GET",
            "url": url
    };
    return settings;
};

在服务器中已完成此操作:

 res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Auth");

0 个答案:

没有答案