我正在使用ShipStation API创建订单,但是遇到错误,无法访问XMLHttpRequest, 下面提供的代码是在https://www.shipstation.com/developer-api/#/reference/orders/createupdate-order/create/update-order?console=1上生成的 所以我在https://tampermonkey.net/扩展名上使用它,该功能在按钮点击错误屏幕截图中调用
(function () {
'use strict';
const $ = window.jQuery;
$(document).ready(function () {
const AUTHKEY = '112233'
$("#send").on("click", sendRequest)
const sendRequest = () => {
var request = new XMLHttpRequest();
request.open('POST', 'https://ssapi.shipstation.com/orders/createorder');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', AUTHKEY);
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = { 'data is correct just deleted for now': '' };
request.send(JSON.stringify(body));
}
});
})();
答案 0 :(得分:0)
该API不适用于客户端。 拨打您自己的后端,然后从那里发送。
发布您的APIKEY非常危险