【发布时间】:2019-04-11 17:45:01
【问题描述】:
您好,我正在使用 Jqgrid,我想在 JqGrid 中显示所有订单列表,但在 Jqgrid 中不显示订单数据。任何专家都可以告诉我我的代码中有什么问题以及为什么我的 jqgrid 中没有显示数据。首先当网格加载时没有错误显示只显示在网格“错误”上,但是当我刷新网格时显示此错误:
访问 XMLHttpRequest 在 'http://api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json' 来自 来源“http://localhost:62797”已被 CORS 策略阻止: 对预检请求的响应未通过访问控制检查: 预检请求不允许重定向。
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>
【问题讨论】:
-
我需要帮助您的 . @T.J.
-
这个域名
'http://api.bigcommerce.com是你的吗 -
您必须在该域上启用 CORS 标头。从这里阅读更多信息 - developer.mozilla.org/en-US/docs/Web/HTTP/CORS
-
这是 api 提供者的域。@front_end_dev
-
请他们启用 CORS 标头。
标签: jquery ajax asp.net-mvc api jqgrid