crossdomain.xml for jQuery?

醉酒当歌 提交于 2019-12-22 11:17:20

问题


I have a blog that's hosted on Tumblr. I have a separate host where I store all the images, js, css, etc for the theme that I made. However, I am also using QueryLoader2 to somehow add a "preloader" for the blog (aka the page will only display a loading bar until everything has loaded).

The problem is, I'm running across Access-Control-Allow-Origin problems since the images and resources are on a different domain. Having experience with flash before, I remember that there is a crossdomain.xml that I can define on the remote server in order for certain domains to be able to access it. But, this is only for Flash. So is there a crossdomain.xml counterpart for JavaScript (or jQuery since that's the framework I'm using)?

It needs to be able to work with QueryLoader2 -> http://www.gayadesign.com/diy/queryloader2-preload-your-images-with-ease/


回答1:


The remote server have to respond with Access-Control-Allow-Origin: * HTTP header, in order for JavaScript to be able to access the files. If you are not preprocessing the response in PHP (or any other server-side language), than you have to setup the web server to add that header. Otherwise you can add it in the script.

If apache web server is used, and it has mod_headers enabled, you can do it in .htaccess

<filesMatch "\.(jpg|png|gif)$">
    <ifModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </ifModule>
</filesMatch>


来源:https://stackoverflow.com/questions/9919305/crossdomain-xml-for-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!