gpt4 book ai didi

javascript - Ajax header 请求 "X-openIDM-Reauth-Password"不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 15:30:00 26 4
gpt4 key购买 nike

我有一个 openIDM 程序,当用户提交更新新密码时,它显示“X-openIDM-Reauth-Password”,其中包括我需要重新输入的旧密码。以下是 openidm 端的屏幕截图。 enter image description here

所以,我有自己的 UI,并且我是从 javascript ajax 端通过以下 ajax 调用发出请求的。

$.ajax({
contentType: "application/json; charset=UTF-8",
datatype: 'json',
url: targetHost+"openidm/managed/user/"+userId,
xhrFields: {
withCredentials: true,
},
headers: {
"X-Requested-With":"XMLHttpRequest" ,
"X-OpenIDM-Reauth-Password": oldPassword
},
crossDomain:true,

data: JSON.stringify(data),
type: 'PATCH',
success:function(result) {
console.log("success");
swal({
title: updateSuccessMsgs.formSubmit.slogan,
text: updateSuccessMsgs.formSubmit.success,
type: "success"
}, function() {
window.location = "my-profile.html";
});
},
error:function (error){
sweetAlert(updateErrorMsgs.updateError.slogan, updateErrorMsgs.updateError.fail, "error");
console.log(error);
}
});

它向我抛出了这个错误。

XMLHttpRequest cannot load http://localhost:9090/openidm/managed/user/09096425-4ff1-42d4-8a4d-3a6b5004afca. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

有人可以解释一下为什么吗?欣赏它。

最佳答案

我找到了解决方案。我尝试在 servlet filter-cors.json 中添加一个值,如下所示。我在“allowedHeaders”中添加了“X-OpenIDM-Reauth-Password”的值,并且成功了。

{
"classPathURLs" : [ ],
"systemProperties" : { },
"requestAttributes" : { },
"scriptExtensions" : { },
"initParams" : {
"allowedOrigins" : "*",
"allowedMethods" : "GET,POST,PUT,DELETE,PATCH",
"allowedHeaders" : "accept,x-openidm-password,x-openidm-nosession,x-openidm-username,content-type,origin,X-OpenIDM-Reauth-Password,x-requested-with",
"allowCredentials" : "true",
"chainPreflight" : "false"
},
"urlPatterns" : [
"/*"
],
"filterClass" : "org.eclipse.jetty.servlets.CrossOriginFilter"
}

关于javascript - Ajax header 请求 "X-openIDM-Reauth-Password"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44877968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com