我正在使用ajax调用以基本身份验证来调用SAP服务。在IE中,如果直接调用该函数会得到有效的响应,但是从SharePoint在线页面调用该函数会给出
“访问被拒绝”错误。在Chrome中,“ 401未经授权”和 “ CORS策略阻止了对XMLHttpRequest的访问。”错误
我已在SAP服务上添加了"Access-Control-Allow-Origin" : "*"
。
var url = sapServiceURL;
$.support.cors = true;
var xhr = $.ajax({
crossDomain: true,
url: url,
type: "GET",
dataType: "json",
contentType: "application/json; charset=utf-8",
headers: {
"accept": "application/json",
"Access-Control-Allow-Origin":"*",
"Authorization" : "Basic " + btoa(username + ":" + userPWD)
},
success: function (response) {
alert("Is Valid flag: "+response.d.results[0].VAlidflag);
},
error: function (response) {
console.log(response)
},
fail: function (response) {
console.log(response)
}
});