Ajax和状态302 [英] Ajax and status 302

查看:476
本文介绍了Ajax和状态302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用AJAX的问题(和/或jQuery的AJAX)和状态302。

I'm having a problem with ajax (and/or jQuery ajax) and status 302.

这就是我想:

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 重定向到一个的.bin 302 code。我不想下载此文件,我只是想知道这个文件的路径。例如:

The some_page_that_I_cant_change.php redirects to a .bin with 302 code. I do not want to download this file, I just want know 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

问题是,Chrome会自动重定向到文件,瞒着我的路径,脚本。是否有解决方法吗?

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

推荐答案

如果您使用的是HEAD请求,而不是GET请求,我怀疑会做你想做的。您应该只看到响应,没有响应主体(即没有.bin文件会下载)头。

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

这篇关于Ajax和状态302的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆