Dojo通过xhrGet读取文件
我正在尝试运行像这样的 xhrGet:
dojo.provide("test");
dojo.declare("test",null,{
getVersion: function(){
details =
{
url: "../version.txt",
content: "test",
handleAs: "text",
timeout: 4000,
load: function(data)
{
console.log("result" + data);
},
error: function(error)
{
console.log("Error" + error);
}
}
var dfd = dojo.xhrGet(details);
return dfd;
});
并且收到此错误:
错误:延迟取消:[异常...“组件返回失败代码:0x80520012(NS_ERROR_FILE_NOT_FOUND)[nsIXMLHttpRequest.send]”nsresult:“0x80520012(NS_ERROR_FILE_NOT_FOUND) )" 位置: "JS 框架:: file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js :: 匿名 :: 第 1351 行“数据:否] 文件:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js 第 0 行
我试图检索的文件是相对于 dojo 的,因此位于 Dojo1.4.3/version.txt 下
其他注意事项...我没有在服务器上运行它,我只是参考加载 html 文件我创建的 dojo 类。
谢谢大家的宝贵时间
编辑
解决方案
我找到了解决方案
https://developer.mozilla.org/en/Same-origin_policy_for_file%3a_URIs
您需要在 Firefox 中启用此策略
I am trying to run an xhrGet like this one:
dojo.provide("test");
dojo.declare("test",null,{
getVersion: function(){
details =
{
url: "../version.txt",
content: "test",
handleAs: "text",
timeout: 4000,
load: function(data)
{
console.log("result" + data);
},
error: function(error)
{
console.log("Error" + error);
}
}
var dfd = dojo.xhrGet(details);
return dfd;
});
and I am getting this error:
Error: Deferred Cancelled: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js :: anonymous :: line 1351" data: no]
file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js
Line 0
The file I am trying to retrieve is relative to dojo, therefore is located under Dojo1.4.3/version.txt
Other note.... I am not running it on a server, I am simply loading the html file with reference to the dojo class I have created.
thank you all for your time
EDIT
SOLUTION
I found the solution
https://developer.mozilla.org/en/Same-origin_policy_for_file%3a_URIs
you need to enable this policy in Firefox
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果出于安全原因或类似原因直接通过
file://
提供页面,则无法执行 AJAX 请求。您需要设置一个 HTTP 服务器并通过该服务器为您的页面提供服务。另外,您在这里使用旧版本的 Dojo 是否有任何特殊原因?当前版本是1.7
You cannot do AJAX requests if your page is being served directly via
file://
, for security reasons or something like that. You will need to set up a HTTP server and serve your page via that.Also, is there any particular reason why you are using an old version of Dojo here? The current version is 1.7