I am new to using JSON (and for jQuery Ajax functions in general). What I'm trying to do is create a separate file containing the JSON object, point to this file, save the object as a variable, and access the properties of the object using dot notation.
jQuery.parseJSON () allows me to do what I want, but I want to take the next step, pointing to a separate file.
For example, the following behavior behaves exactly as I expected by opening a warning window that says “red”:
var test = $.parseJSON('{"simple":"red"}');
alert(test.simple);
The following indicates that points to a file containing the same JSON object does not work, opening a warning window that says "undefined":
var test = $.getJSON('simple.json');
alert(test.simple);
I obviously do not use it correctly. What is the right way to do what I'm trying to achieve here?
user693094
source
share