Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am having a data.json file containing...
{"C13":0,"C24":0,"C35":0,"C46":0,"C57":0,"C12":105.23,"C23":0.18,"C34":124.3,"C45":132.49,"C56":145.39,"C14":60.46,"C25":0.18,"C36":84.3,"C47":93.24,"C58":97.7,"C1":146.78,"C2":0,"C3":94.15,"TS":"16:55:24"}


now I have to get the values in javascript...

alert returning "undefined"..

need help...

What I have tried:

<script src="js/jquery.min.js"></script>


<script type="text/javascript">
$.ajax({
	url: "data.json",
	dataType: "json",
	success: function(data){
	var f = data.c1;
	alert(f);
	alert("test");
	}


});

</script>
Posted
Updated 10-Mar-19 12:13pm
v2

1 solution

Because your object contains a property C1, not c1. JavaScript is case-sensitive, and you need to take care of that. Use this,
JavaScript
var f = data.C1;
Since your alert is showing undefined, it clearly means that the property is undefined, the object is not. If the data was undefined, it would have said "cannot read property 'c1' of undefined". If, however, the data was of another type, then it would have said something or similar to the second error.
 
Share this answer
 
Comments
ramen79 11-Mar-19 5:38am    
Oops!
thanks. It is working now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900