我有一个设置,其中有一个基本域和多个子域。
例如,
根据我的一个用例,我需要从在基础域中运行的门户访问在子域中运行的服务。
也就是说,
在尝试触发Jquery ajax时,我收到如下所示的CORS异常。
从源“ https://rei.la.ca.jing.xxxxx.com/MiDAS/UPDATE”到“ https://jing.xxxxx.com”的XMLHttpRequest的访问已被CORS策略阻止:Access-Control不允许请求头字段access-control-allow-origin -允许标头在飞行前响应
下面是我尝试过的代码。
return new Promise((resolve, reject) => {
let url = url_midasService + "UPDATE";
let finalSettings = {};
finalSettings.url = url;
finalSettings.success = function (msg) {
console.log("SUCCESS::" + url);
resolve(msg);
};
finalSettings.error = function (jqXHR) {
console.log("FAILURE::" + url);
reject(jqXHR.status);
};
finalSettings.type = "PUT";
finalSettings.data = JSON.stringify(payload);
finalSettings.contentType = "application/json";
finalSettings.crossDomain = true;
finalSettings.headers = {
'Access-Control-Allow-Origin': '*'
};
finalSettings.xhrFields = {
withCredentials: true
};
$.ajax(finalSettings);
});
以下是一些额外的信息:
预先感谢:-)