【发布时间】:2020-09-12 06:33:04
【问题描述】:
我正在尝试使用 jQuery 访问 NetSuite restlet。这是我的代码:
jQuery.ajax({
url: "https://rest.na2.netsuite.com/app/site/hosting/restlet.nl?script=270&deploy=1&searchId=customsearch_active_models",
type: "GET",
dataType: "json",
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "NLAuth nlauth_account=ACCOUNT#, nlauth_email=EMAIL, nlauth_signature=XXXXXX, nlauth_role=ROLE#")
}
})
.done(function(data){
console.log(data);
});
当我在 Chrome/FF 中检查“网络”标签时,它给了我以下 401 响应:
XMLHttpRequest cannot load https://rest.na2.netsuite.com/app/site/hosting/restlet.nl?script=270&deploy=1&searchId=customsearch_active_models. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.tracksandtires.com' is therefore not allowed access. The response had HTTP status code 401.
我没有正确格式化授权部分吗?我找不到任何关于通过 jQuery 访问 NetSuite Restlet 的文档,所以我在这里有点盲目。我应该只使用 vanilla javascript 而不是 jQuery 吗?任何帮助将不胜感激!
【问题讨论】:
标签: javascript jquery netsuite