Probably a simple one for an expert:
I have a json file called newport.json located in the www folder. The json is as follows:
{"nmech":"3.00","nelect":"3.00","nplant":"0.00","ncivil":"55.00"}
I have my JS to load in via ajax:
$.ajax({
url:'newport.json',
datatype:'json',
type:'get',
cache:false,
success:function(data){
$(data).each(function(index,value){
console.log(value);
});
}
});
My issue is the console log produces the following from the above js:
Object {nmech: "3.00", nelect: "3.00", nplant: "0.00", ncivil: "55.00"}
but I seem to be struggling to then get a value say nmech passed into a javascript variable.
Thanks in advance for any help.
datashould have yourObjectconsole.log(data.nmech);should produce3.00...data.nmechwithout the each loop. do you have multiples of these or is it just this?var nmech = data.nmech