AJAX - Get response URL after redirect

后端 未结 1 495
野性不改
野性不改 2021-01-07 01:32

I was wondering if there is a way to get the URL of the returned resource after a AJAX call in JavaScript?

I want to use this with a form, which is in \"mysite.com/u

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 02:05

    Solved this by setting the response header "Location" in a Java Filter.

      HttpServletRequest httpRequest = (HttpServletRequest) request;
      HttpServletResponse httpResponse = (HttpServletResponse) response;
      String path = httpRequest.getRequestURI();
      httpResponse.setHeader("Location", path);
    

    In JavaScript I could then use

      XMLHttpRequest.getResponseHeader("Location")
    

    Hopefully this won't cause any unforeseen problems. :P

    If anyone else have an easier solution though I'd like to see it.

    0 讨论(0)
提交回复
热议问题