Ajax and status 302

I have a problem with ajax (and / or jQuery ajax) and status 302.

Here is what I am trying:

var xhr = new XMLHttpRequest(); xhr.open("GET", 'some_page_that_I_cant_change.php'); xhr.onreadystatechange = function(){ console.log(xhr.readyState, xhr.status); }; xhr.send(null); 

some_page_that_I_cant_change.php redirects the .bin code with the 302 code. I do not want to download this file, I just want to find out the path to the file. Example:

 ./some_page_that_I_cant_change.php ./path/to/bin/file.bin << I wan't only this path as string 

The problem is that Chrome automatically redirects the file without telling me the path to the script. Is there a workaround for this?

+2
source share
3 answers

If you use the HEAD request instead of the GET request, I suspect that I will do what you want. You should see only the headers in the response, the body of the response (i.e. No .bin will be loaded).

+2
source

There is an older topic about the same topic with solutions and work: How to manage a redirect request after jQuery Ajax call

0
source

In a word: I do not think you can do this reason for the HTTP protocol.
The HTTP protocol ([1]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ) provides 302 means URI redirection, and browsers follow. This way javascript cannot get the redirect response, just get the final answer.

So, you need to get the path through the body of the answer.

0
source

Source: https://habr.com/ru/post/1447533/


All Articles