Mojimi
Mojimi

Reputation: 3161

Require JSON file with DOJO

I'm using define/declare from the Dojo API to load modules, but I also want to load a .json config file, but it is ignoring the extension and trying to load a .js file

define([
        "./Config.json",
        "dojo/domReady!"
    ],
    function(
        config
    ){ 
    var config = JSON.parse(config);
    console.log(config);
})

Through the console I can see it is trying to load "Config.json.js" instead of "Config.json", how can I solve this?

Upvotes: 1

Views: 480

Answers (1)

Bourbia Brahim
Bourbia Brahim

Reputation: 14702

I think dojo/text plugin could help you

try to load the file as bellow ( be sur of the path to your file )

define([
    "dojo/text!./Config.json",
    "dojo/domReady!"
],
function(config){ 
    var config = JSON.parse(config);
    console.log(config);
})

Upvotes: 1

Related Questions