【发布时间】:2018-11-09 05:37:26
【问题描述】:
我正在使用 big commerce API 来获取订单列表,我尝试了很多解决方案。
这是我面临的错误..
api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json?search=false&nd=1541740677952&rows=20&page=1&sidx=&sord=asc:1 加载资源失败:服务器响应状态为 401(未授权)索引:1 从源“http://localhost:62797”对“https://api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json?search=false&nd=1541740677952&rows=20&page=1&sidx=&sord=asc”的 XMLHttpRequest 的访问已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:没有“Access-Control-Allow-Origin”标头出现在请求的资源上。
HTML
<table id="JqGrid"></table>
<div id="JqGridPager"></div>
jQuery
<script type="text/javascript">
jQuery(document).ready(function ($) {
var $grid = $("#JqGrid");
$grid.jqGrid({
url: 'https://api.bigcommerce.com/stores/4jwabif3gj/v2/orders.json',
ajaxGridOptions: { xhrFields: { withCredentials: true } },
dataType: 'json',
colNames: ['id', 'date_created', 'date_modified', 'date_shipped', 'status'],
colModel: [
{ name: 'id', index: 'id', width: 10 },
{ 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: "Order list",
pager: "#JqGridPager",
loadBeforeSend: function (jqXHR) {
jqXHR.setRequestHeader("X-Auth-Token", 'modebafppdxh9sd90zffehu9wwgpj3d', "X-Auth-Client", '535bnhhfkqblu7ebg1aq9r6kue1lgv6');
},
//ajaxGridOptions: {
// beforeSend: function (xhr) {
// xhr.setRequestHeader("X-Auth-Token", "modebafppdxh9sd90zffehu9wwgpj3d", "X-Auth-Client", "535bnhhfkqblu7ebg1aq9r6kue1lgv6");
// }
//},
viewrecords: true,
width: 1100,
height: 400
});
$grid.jqGrid('navGrid', '#JqGridPager', { edit: false, add: false, del: false })
});
</script>
【问题讨论】:
-
我需要你的帮助来解决这个问题。 @Alyss
标签: jquery ajax model-view-controller jqgrid bigcommerce