首页 > 解决方案 > 获取 Cors 策略错误本地主机无法运行

问题描述

我在运行本地主机时收到此消息,因为我在 Net SuiteCommerce 高级电子商务网上商店工作,但从最近两天开始,我收到此错误。我在 Stackoverflow 和其他一些网站上搜索过它,但没有得到任何令人满意的解决方案,所以我将它发布在这里。

尝试下载 Cors 扩展并激活,但它不起作用。除了谷歌浏览器之外,本地主机运行良好。

define(
    'JJRename.Rename.Rename'
,   [
        'Utils',
        'MenuTree.View',
        'Header.Menu.MyAccount.View',
        'JJRename.Rename.Rename.View'
    ]
,   function (
        Utils,
        MenuTreeView,
        HeaderMenuMyAccountView,
        RenameView
    )
{
    'use strict';

    return  {
        mountToApp: function mountToApp (container)
        {
            var layout = container.getComponent('Layout');

            _.extend(MenuTreeView.prototype,{
                getContext: _.wrap(MenuTreeView.prototype.getContext, function (fn){
                    var changeName = fn.apply(this, _.toArray(arguments).slice(1));
                    var array = changeName.menuItems;

                    _.each(changeName.menuItems, function (second){
                        _.each(second.children, function (children){
                            if(children.name == "Email Preferences"){
                                children.name = "Subscriptions"
                            }
                        });
                    });
                    return changeName;
                })
            });
            _.extend(HeaderMenuMyAccountView.prototype, {
                getContext: _.wrap(HeaderMenuMyAccountView.prototype.getContext, function (fn){
                    var helloWorld = fn.apply(this, _.toArray(arguments).slice(1));
                    console.log("first", helloWorld)
                    _.each(helloWorld.entries, function (first){
                        _.each(first.children, function (children){
                            if(children.name == "Email Preferences"){
                                children.name = "Subscriptions"
                            }
                        });
                    });
                    return helloWorld;
                })
            });
        }
    };
});

Access to XMLHttpRequest at 'http://localhost:7777/who/shopping' from origin 'http://www.cricketsca.ml' has been blocked by CORS policy: 

请求客户端不是安全上下文,资源位于更私密的地址空间local中。

shopping-local.ssp:1 从源“http://www.cricketsca.ml”访问“http://localhost:7777/extensions/J_J/JJ_Base_Theme/3.0.2/img/favicon.ico”的资源有被 CORS 策略阻止:请求客户端不是安全上下文,资源位于更私密的地址空间local中。

标签: javascriptnode.jsgoogle-chromecorssuitecommerce

解决方案


这可能是因为最近的 Google Chrome 更新。之前也有过类似的问题,但有一些变通办法。现在您可以尝试其他浏览器(例如 Firefox)。


推荐阅读