-1

So I have referenced Loading local JSON file & load json into variable and tried loading my own json file into a variable that I want to display, but I still seem to get no values to appear. The json file is local/in the same directory. I believe I have not loaded the file correctly. Is there any errors I didn't catch?

I also tried using $.getJSON and the require.js method, and that didn't work either.

Here is my JSON File:

{
  "IMax": 16384, 
  "IMin": 1,
  "DynamicRange": 72,
  "I50": 16,
  "I75": 192
}

Here is my code:

<!DOCTYPE html>
<html>

<head>
<script src="jquery-3.2.1.min.js"></script>
</head>
<body>
<p id="parameterForm"></p>

<script>
//Where the JSON File should be loaded
var json = (function () {
    var json = null;
    $.ajax({
        'async': false,
        'global': false,
        'url': "Parameters.json",
        'dataType': "json",
        'success': function (data) {
            json = data;
        }
    });
    return json;
})(); 
document.getElementID("parameterForm").innerHTML = json.IMax;
</script>

</body>
</html>  
FLCL
  • 67
  • 1
  • 12
  • Put the error block also at Ajax request. Is there any Ajax error you have seen at console? – Volem Jul 19 '17 at 18:09
  • @Volem How would I go about doing that? ELI5 please! and I am not sure, I am doing all of this through notepad++ – FLCL Jul 19 '17 at 18:15
  • 3
    You have a syntax error, it should be `document.getElementById`. Fixing that one thing, you code worked example worked fine when I tried it. – aalcutt Jul 19 '17 at 18:16
  • 2
    synchronous calls are a bad idea. – epascarello Jul 19 '17 at 18:16
  • @aalcutt Thanks for catching that! I just fixed it and still getting a blank screen, I wonder how it worked for you but not me. – FLCL Jul 19 '17 at 18:19
  • Check the console of the dev tools to see if there are any errors. – aalcutt Jul 19 '17 at 18:23
  • Removed my answer, I missed that the request is already sync – Volem Jul 19 '17 at 18:24
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Heretic Monkey Jul 19 '17 at 18:32

1 Answers1

-2

If you are doing this on your local machine you will get a Cross Origin Request Sharing error similar to these:

CORS error

You can verify this by opening the dev console.

If your site is loaded from remote, you should be able to load the json normally with ajax.