Dojo使用dojo.xhrGet从本地文件系统读取json文件
问题描述:
我试图从本地文件系统读取文件。我没有可用的服务器,因此我试图这样做。这是我到目前为止;Dojo使用dojo.xhrGet从本地文件系统读取json文件
function init(){
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserWrite');
dojo.xhrGet(
{
url: "/json/coursedata.json",
handleAs:"json",
load: function (type, data, evt) {alert (data) },
//mimetype: "text/plain"
});
}
我从萤火虫控制台收到这个错误;
Access to restricted URI denied" code: "1012
http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js
Line 16
答
该解决方案很简单。幸运的是,访问本地文件系统上的文件并不被视为跨域请求。所以如果getCourse(course)
是通过点击按钮来调用的。dojo.xhrGet
在名为json的文件夹中检索文件过程。对象数据是对象格式中的json文件的内容。
function getCourse(course)
{
dojo.xhrGet({
url: "json/" + course,
handleAs: "json",
handle: function(data,args){
populate_table(data);
}
});
}