Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取图像文件的重定向url_Javascript_Jquery - Fatal编程技术网

Javascript 获取图像文件的重定向url

Javascript 获取图像文件的重定向url,javascript,jquery,Javascript,Jquery,我正在尝试获取存储在S3中的图像的重定向URL。由于一些CORS问题,我尝试使用AJAX调用和JSONP来实现。但我有一个问题: Refused to execute script from '...' because its MIME type ('image/jpeg') is not executable. 我不想打开文件或遵循重定向。我只需要URL。 function getRedirect(url) { var settings = { 'cache': fal

我正在尝试获取存储在S3中的图像的重定向URL。由于一些CORS问题,我尝试使用AJAX调用和JSONP来实现。但我有一个问题:

Refused to execute script from '...' because its MIME type ('image/jpeg') is not executable.
我不想打开文件或遵循重定向。我只需要URL。

function getRedirect(url) {

var settings = {
          'cache': false,
          'dataType': "jsonp",
          "crossDomain": true,
          "url": url, 
          "method": "GET",
          "headers": {
              "accept": "application/json",
              "Access-Control-Allow-Origin":"*"
          }
      };
      
$.ajax(settings).success(function (result,status,xhr) {
  var r = xhr.getResponseHeader('Location');
  console.log(r);
  return r;
});

};

我自己没有尝试过,因为我没有时间设置重定向服务

fetch(url{
重定向:“手动”,
})。然后(响应=>{
log(response.url);
});

Thx无法工作,因为“…已被CORS策略阻止:请求的资源上没有“Access Control Allow Origin”头…”我添加了{mode:“No CORS”}但没有成功,这不取决于您。如果服务器不执行CORS,或者您不是从允许的服务器(localhost通常不是)调用,那么您将需要一个代理。听起来是个好主意。url是源url!您需要在服务器端执行此操作