I am not able to parse the json data by the following code, its not even giving any alert please tell me where i have mistaken
when i am using the json content in an array then no issues are there but when i am attaching it to a file nothing haapens
$(document).ready(function(){
$.getJSON("dat.js",function(data){
$.each(data.posts,function(i,data){
alert(data.title);
});
});
});
my json file is
{
"posts":
[
{
"title":"ajax | Programming ",
"url":"hello"
},
{
"title":"jQuery and Ajax Demos Pard - 3",
"url":"how are you"
},
]
}
Your code is correct (check http://jsfiddle.net/mX4E2/) so the problem must be that your file is not reached by
$.getJSON. Have you checked with firebug that the call is correct?EDIT – remove the last comma from the json, otherwise IE will complain