Reputation: 2424
I am trying to get the value from the serverside but i can't get it..Here, i am trying to convert the json data using JSON.parse(); but it is not working in jQuery... i don't know how to solve this...
$(document).ready(function() {
$.ajax({
url:'http://newslet.comxa.com/NewsRecord.php' ,
dataType:'json',
success:function(output_string) {
temp=JSON.parse(output_string);
for(var i=0;i<temp.length;i++)
{
$('#level').append('<div>Title :'+temp[i].Title+'<br>Source :<a href='+temp[i].links+'>'+temp[i].Source+'</a><br>Category :'+temp[i].Category+'</div><hr>');
}
}
});
});
i get this output when i am running these path 'http://newslet.comxa.com/NewsRecord.php'..
[{"Id":"2","Date":"","Title":"Hitachi Data Systems bets big on analytics","Source":"TOI","Category":"Corporate","links":"http:\/\/timesofindia.indiatimes.com\/tech\/tech-news\/software-services\/Hitachi-Data-Systems-bets-big-on-analytics\/articleshow\/26542988.cms?"},{"Id":"3","Date":"","Title":"British bike company Triumph drives into India","Source":"TOI","Category":"Industry","links":"http:\/\/timesofindia.indiatimes.com\/business\/india-business\/British-bike-company-Triumph-drives-into-India\/articleshow\/26542881.cms"}]
Upvotes: 0
Views: 139
Reputation: 10694
Your string already is a valid json so there isnt any need to use
JSON.parse(output_string);
Check this fiddle http://jsfiddle.net/uDr6t/
Upvotes: 0
Reputation: 26312
you need to stringify first json result.
var json = JSON.stringify([{"Id":"2","Date":"","Title":"Hitachi Data Systems bets big on analytics","Source":"TOI","Category":"Corporate","links":"http:\/\/timesofindia.indiatimes.com\/tech\/tech-news\/software-services\/Hitachi-Data-Systems-bets-big-on-analytics\/articleshow\/26542988.cms?"},{"Id":"3","Date":"","Title":"British bike company Triumph drives into India","Source":"TOI","Category":"Industry","links":"http:\/\/timesofindia.indiatimes.com\/business\/india-business\/British-bike-company-Triumph-drives-into-India\/articleshow\/26542881.cms"}]);
var temp = JSON.parse(json);
Upvotes: 1