简体   繁体   English

OpenSeadragon跨域Ajax请求

[英]OpenSeadragon Cross Domain Ajax request

TL;DR: How can I make a Cross-Domain AJAX request with OpenSeadragon? TL; DR:如何使用OpenSeadragon进行跨域AJAX请求?

I'm using OpenSeadragon to display images from a website. 我正在使用OpenSeadragon显示网站上的图像。 I have my Seadragon viewer working with a test URL as follows: 我的Seadragon查看器使用以下测试URL:

<script src="../../Scripts/openseadragon/openseadragon.js"></script>

<script>
var viewer = OpenSeadragon({
    id: "openseadragon1",
    prefixUrl: "../../Scripts/openseadragon/images/", 
    tileSources: "https://familysearch.org/dz/v1/TH-1971-27860-10353-27/image.xml?ctx=CrxCtxPublicAccess&session" // requires a DZI tile source
});
</script>

<div id="container2" style="float:left;">
    <div id ="openseadragon1" style="width:500px;height:500px;border:1px solid black;float:left;"></div>
</div>

so I know my viewer is working. 所以我知道我的观众正在工作。 My problem is that the specific images I need are hosted on a site that does not have a "Access-Control-Allow-Origin" header, so my Ajax request is getting blocked. 我的问题是,我需要的特定图像托管在没有“ Access-Control-Allow-Origin”标头的网站上,因此我的Ajax请求被阻止了。 For example, when I use this URL: 例如,当我使用此URL时:

http://66.img.americanancestors.org/e41de95d-6235-4581-b823-4887b50eb8ad.xml

(which I am able to access in my browser, when I type it in it downloads an xml file), I get the "No Access-Control-Origin-Header" error and this error in my viewer: (我可以在浏览器中访问它,当我在浏览器中键入它时下载一个xml文件),我收到“ No Access-Control-Origin-Header”错误,并在查看器中出现此错误:

海龙错误

I know about Cross Domain requests, but being new to OpenSeadragon, I'm not sure how to create a cross-domain request in my OpenSeadragon function. 我知道跨域请求,但是对于OpenSeadragon来说是新手,所以我不确定如何在OpenSeadragon函数中创建跨域请求。 I know that OpenSeadragon has a CreateAJAXRequest() function, but I don't really understand how to implement it, and I'm not sure if that would solve my problem. 我知道OpenSeadragon有一个CreateAJAXRequest()函数,但是我不太了解如何实现它,我不确定这是否可以解决我的问题。

Your browser is correctly refusing to load data from a cross-domain source that doesn't set "Access-Control-Allow-Origin". 您的浏览器正确地拒绝从未设置“ Access-Control-Allow-Origin”的跨域源加载数据。 Three possible solutions: 三种可能的解决方案:

  • Make a copy of the xml and host it on your own site 复制xml并将其托管在您自己的站点上
  • Make a request to your own site, which acts as a proxy and fetches the remote xml file 向您自己的站点发出请求,该站点充当代理并获取远程xml文件
  • Kindly ask the site owner to set up CORS headers for you 请让网站所有者为您设置CORS标头
  tileSources: url,
  ajaxWithCredentials : true,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM