• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

How to load config data from file?

Scheduled Pinned Locked Moved Unsolved Troubleshooting
12 Posts 4 Posters 4.0k Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    idoodler Module Developer @acimail01
    last edited by idoodler Jul 21, 2019, 9:43 PM Jul 21, 2019, 9:41 PM

    @acimail01 Ok, we can fix the $ is not defined at loadJSON.

    Replace the function with the following which uses good old XMLHttpRequest:

    fuction loadJSON(filePath) {
        if (typeof module !== "undefined") {
            return require(filePath);
        } else {
            try {
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open("GET", filePath, false);
                xmlhttp.send();
                if (xmlhttp.status === 200) {
                    return JSON.parse(xmlhttp.responseText);
                } else {
                    throw "Unexpected status code!";
                }
            } catch (e) {
                console.error(e);
                return {};
            }
        }
    }
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      telmini
      last edited by Jan 25, 2021, 11:57 PM

      Did you manage to make this work? I’m trying to do kinda the same.

      Thanks

      1 Reply Last reply Reply Quote 0
      • 1
      • 2
      • 2 / 2
      • First post
        Last post
      Enjoying MagicMirror? Please consider a donation!
      MagicMirror created by Michael Teeuw.
      Forum managed by Sam, technical setup by Karsten.
      This forum is using NodeBB as its core | Contributors
      Contact | Privacy Policy