如何从只使用JS另一个域加载文件内容是什么? [英] How to load file contents from another domain using just JS?

查看:157
本文介绍了如何从只使用JS另一个域加载文件内容是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在做面向移动用户的一些网上的文件操作的想法是,用户提供一个URL到文件,那么该文件内容由JS修改,然后可以下载。但我一直无法弄清楚如何获得文件时,它的使用JS只是一个单独的域。

I'm thinking of doing some online file manipulation for mobile users, the idea being that the user provides a URL to the file, then the file contents are modified by the JS, and can then be downloaded. But I haven't been able to figure out how to get the file when it's on a separate domain using just JS.

这可能吗?如果是这样任何提示或例子是AP preciated。

Is this possible? If so any hints or examples would be appreciated.

只是想补充的是我想要做的是使其可没有我收留了它的一部分。我想的有点像,他们可以的地方举办一个文件,然后所有的带宽是自己......这无论他们是从课程获得的文件。

Just wanted to add that part of what I wanted to do was make it available without my hosting it. I'm thinking of something like a a file they can host somewhere,and then all of the bandwidth is their own...and that of wherever they are getting the file from of course.

推荐答案

加载另一个域上的文件的内容的唯一方法是从内<脚本> 标签。这是 JSONP 是如何工作的。考虑让你的目标文件到这种格式。

The only way to load contents of a file on another domain is from within a <script> tag. This is how JSONP works. Look into getting your target file into this format.

另一种方法是使用一个本地代理。创建加载并返回文件内容的Web服务方法,然后调用本地使用自己喜欢的JavaScript框架。

The other way would be to use a local proxy. Create a web service method that loads and returns the contents of the file, then call that locally using your favorite JavaScript framework.

这篇关于如何从只使用JS另一个域加载文件内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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