Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
Ajax 访问控制允许源不允许从远程服务器获取HTTP_Ajax_Url Rewriting_Cors_Same Origin Policy - Fatal编程技术网

Ajax 访问控制允许源不允许从远程服务器获取HTTP

Ajax 访问控制允许源不允许从远程服务器获取HTTP,ajax,url-rewriting,cors,same-origin-policy,Ajax,Url Rewriting,Cors,Same Origin Policy,我正在使用Ajax使用HTTP下载XML,但出现以下错误: XMLHttpRequest cannot load https://remoteserverfqdn:8444/cuic/permalink/PermalinkViewer.htmx?viewId=F52A08751000014B3835F5E80AB43E68&linkType=xmlType&viewType=Grid. No 'Access-Control-Allow-Origin' header is pres

我正在使用Ajax使用HTTP下载XML,但出现以下错误:

XMLHttpRequest cannot load https://remoteserverfqdn:8444/cuic/permalink/PermalinkViewer.htmx?viewId=F52A08751000014B3835F5E80AB43E68&linkType=xmlType&viewType=Grid. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 403.
我用于获取数据的代码:

$(document).ready(function()
{
  $.ajax({
    type: "GET",
    url: "https://remoteserverfqdn:8444/cuic/permalink/PermalinkViewer.htmx?viewId=F52A08751000014B3835F5E80AB43E68&linkType=xmlType&viewType=Grid",
    dataType: "xml",
    success: parseXml
  });
});
远程服务器是一个黑盒,所以在这方面我无能为力,无法启用访问控制。我尝试在IIS上安装ARR和URL重写以充当反向代理。当直接在浏览器中访问页面时,这很好,但是当使用Ajax和HTTP GET时,它会给我同样的错误

有人知道我可以使用另一种方法绕过CORS下载xml吗?我确实读过JSONP,但我认为服务器端的一个变化——黑盒(blackbox)需要改变,才能工作吗


如果ARR和URL重写是正确的方法,是否有人知道是否有一个设置可用,我无法将原始HTTP头设置为远程服务器URL。

您是否尝试过contentType:text/plain和/或头:{'X-request-With:','XMLHttpRequest'}?刚刚尝试过这两种设置,结果相同。虽然我不确定是否正确添加了headers部分,但要添加它而不出现错误,唯一的方法是:headers:X-request-With:XMLHttpRequest,正如我的评论中所说,text/plain be quote我确实找到了解决此问题的方法。blackbox实际上提供了一种方法,可以用来代替不受CORS影响的ajax。该方法称为gadgets.io.makeRequest。