2017-07-03 39 views
1

我有一个openID程序,当用户提交更新新密码时,它显示“X-openIDM-Reauth-Password”,其中包含我需要的旧密码重新输入。以下是openidm方面的截图。 enter image description hereAjax Header请求“X-openIDM-Reauth-Password”不起作用

所以,我有我自己的用户界面,我是来自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. 

有人能解释我为什么吗?欣赏它。

+1

lookup ** CORS ** - 服务器没有发送头允许客户端“访问”资源 - 注意:因为这是一个* preflight *错误,它可能仅仅是服务器不会不明白如何处理** OPTIONS **请求方法 –

+1

您还需要在服务器上添加'Access-Control-Allow-Origin:*'标头。 –

回答

1

我找到了解决方案。我尝试在servletfilter-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" 
} 
+0

您可以将自己的答案标记为解决方案。 –