2017-07-03 10 views
1

私はopenIDMプログラムを持っています。ユーザが新しいパスワードを更新すると、必要な古いパスワードを含む「X-openIDM-Reauth-Password」再入力する。以下はopenidm側からのスクリーンショットです。 enter image description hereAjax Headerリクエスト「X-openIDM-Reauth-Password」が機能しない

私自身の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. 

誰かが私の理由を説明できますか?感謝します。

+1

検索** CORSは、** - サーバーは、「アクセス」にリソースをクライアントを許可するようにヘッダを送信していない - 注意:これは*プリフライト*エラーであるとして、それは単にサーバがdoesnのことが考えられ** 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

自分の答えを解決策としてマークすることができます。 –

関連する問題