views:

568

answers:

1

Hello,

I'm trying to read a file from a local filesystem. I do not have a server at my disposal and thus i'm trying to do it this way. Here is what I got so far;

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" 
    });
}

I'm getting this error from the firebug console;

Access to restricted URI denied"  code: "1012
http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js
Line 16
A: 

The solution was simple. Luckily accessing a file on your local file system, is not seen as a cross-domain request. So if the getCourse(course) is called by clicking on a button etc. The dojo.xhrGet retrieves the file course in the folder named json. The object data is the contents of the json file in the object format.

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