2

これは私のajaxスニペットです

$.ajax({
  url: url,
  type: "POST",
  success: function(response, statusText, xhr) {
    if (xhr.status == 302 || xhr.status == 0) {
  window.location = xhr.getResponseHeader("Location");
      window.location.reload();
}
    else {
  success();
}
  },
  error: function (xhr) {
    if (xhr.status == 302 || xhr.status == 0 || (xhr.getResponseHeader("Content-Type").indexOf("text/html") == 0)) {
      window.location = xhr.getResponseHeader("Location");
      window.location.reload();
    }
  }
});

サーバーが 302 コードを返したときにページ全体をリロードしたい。

上記のスニペットは、アプリケーション サーバー (私の場合は WebSphere) に直接アクセスするとうまく機能します。

しかし、Web サーバーで同じものにアクセスすると、Web サーバーはアプリケーション サーバーから返された 302 要求を受け取り、ログイン ページのコンテンツをリダイレクトして応答として送信します。そのため、ページの一部がログイン ページのコンテンツで更新されます。

この Web サーバーの場合、ページをリロードしたいと考えています。ajax はステータス コード 200 を取得しています。

4

0 に答える 0