来源已被 CORS 策略阻止对预检请求的响应未通过访问控制检查

origin has been blocked by CORS policy Response to preflight request doesn't pass access control check

您好,我正在使用 Jqgrid,我想在 JqGrid 中显示所有订单列表,但在 Jqgrid 中不显示订单数据。任何专家都可以告诉我代码中的问题是什么以及为什么数据没有显示在我的 jqgrid 中。首先当网格加载时没有错误显示只显示在网格 "error" 上,但是当我刷新网格时显示此错误:

Access to XMLHttpRequest at 'http://api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json' from origin 'http://localhost:62797' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

HTML

<table id="JqGrid"></table>
 <div id="JqGridPager"></div>

JQuery

   <script type="text/javascript">

    jQuery(document).ready(function ($) {
        var $grid = $("#JqGrid");
        $grid.jqGrid({
            url: 'http://api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json',
            datatype: 'json',
           ajaxGridOptions: { xhrFields: { withCredentials: true } }, 

           colNames: ['id', 'billing_address', 'date_created', 'date_modified', 'date_shipped', 'status'],
            colModel: [
                { name: 'id', index: 'id', width: 10 },
                { name: 'billing_address', index: 'billing_address', width: 50 },
                { name: 'date_created', index: 'date_created', width: 50, sorttype: 'date', datefmt: 'Y-m-d' },
                { name: 'date_modified', index: 'date_modified', width: 50, sorttype: 'date', datefmt: 'Y-m-d' },
                { name: 'date_shipped', index: 'date_shipped', width: 50, sorttype: 'date', datefmt: 'Y-m-d' },
                { name: 'status', index: 'status', width: 50 },
            ],
            caption: "Employees",
            pager: "#JqGridPager",
            loadBeforeSend: function (jqXHR) {
                jqXHR.setRequestHeader("X-Auth-Client", 'clientstring', "X-Auth-Token", 'tokenid');
            },
            viewrecords: true,
            width: 1100,
            height: 400
        });
        $grid.jqGrid('navGrid', '#JqGridPager', { edit: false, add: false, del: false })
    });
</script>

如果您真的很想使用该网站,我认为您唯一的选择是通过您控制的网站代理它。在您的网站上,启用并支持 CORS,您的页面调用您的服务,您的服务调用目的地并将响应传递到您的页面。

虽然这是一个技术上正确的答案,可以解除对您的封锁,但我认为您应该考虑到您正在为自己的目的使用他人的资源。他们可能出于某种原因阻止 CORS 访问。采纳此建议可能会违反该网站的使用条款,后果自负。

要么联系网站并根据您的需要制定交易,要么找到他们拥有您想要的任何数据的不同来源。