我想将 HTML div 从托管在 windows azure blob(我自己的)上的 html 文件加载到同样托管在 windows azure web Angular 色上的 MVC View (blob 和 web Angular 色都归我所有) .
我尝试使用 jquery.load(),但它遇到了跨域问题,并且窗口 azure blob 不允许更改 CORS
策略。接下来我尝试使用Require.Js和 Text.Js来实现这种跨域负载。
来自 Text.Js
文档:
Text plugin determines that the request for the resource is on another domain, it will try to access a ".js" version of the resource by using a script tag. Script tag GET requests are allowed across domains. The .js version of the resource should just be a script with a define() call in it that returns a string for the module value.
我使用 require.js 进行跨域调用的 js 代码是:
require(["text!http://xxxxx.blob.core.windows.net/xxx/File"],
function (html) {
alert(html);
}
);
现在我面临的问题是文件的 .js 版本已由插件成功加载(通过使用 chrome 检查器确认),但在回调中,当我尝试访问以下文本内容时文件,它显示未定义。我在这里做错了什么,为什么回调没有文本内容?有人可以帮我解决这个问题吗?如果这是无法解决的,我愿意接受其他方法来实现这种跨域负载。
我对 require.js 文档的理解是,跨域调用可以通过调用资源的 javascript 版本来完成。
最佳答案
尝试使用定义
:
define(["text!http://xxxxx.blob.core.windows.net/xxx/File"], function (html) {
return {
template: html;
}:
}
);
关于javascript - 使用 require.js 进行跨域调用时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14173476/