2010-04-10 175 views
0

我試圖從本地文件系統讀取文件。我沒有可用的服務器,因此我試圖這樣做。這是我到目前爲止;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 

回答

1

該解決方案很簡單。幸運的是,訪問本地文件系統上的文件並不被視爲跨域請求。所以如果getCourse(course)是通過點擊按鈕來調用的。dojo.xhrGet在名爲json的文件夾中檢索文件過程。對象數據是對象格式中的json文件的內容。

function getCourse(course) 
{ 
    dojo.xhrGet({ 
     url: "json/" + course, 
     handleAs: "json", 
     handle: function(data,args){ 
      populate_table(data); 
     } 
    }); 
}