AJAX redirect dilemma, how to get redirect URL OR how to set properties for redirect request

前端 未结 6 497
甜味超标
甜味超标 2021-02-01 05:47

First, I\'m working in Google Chrome, if that helps. Here is the behavior:

I send an xhr request via jQuery to a remote site (this is a chrome Extension, and I\'ve set a

6条回答
  •  被撕碎了的回忆
    2021-02-01 06:04

    As Rajiv M. has stated above, you cannot catch 302 redirects using an XHL Object or AJAX request.

    Your best bet is to setup a proxy of some kind in PHP/ASP or whatever server-side scripting language. The PHP script will simply follow 302 redirects until it reaches a final destination. Then, it can send the final URL back to your JavaScript page. Now future AJAX requests can be sent directly to the known final URL.

    Or...

    Your PHP script will just serve as a proxy. All requests will be sent to this PHP script.

    Or...

    Just hardcode the final URL into your JavaScript application, if possible (although I assume that it's not possible in your case).

    Sorry -- I hate the "you can't do this" answers, too, but there are some JavaScript limitations that haven't quite been ironed out yet.

提交回复
热议问题