Reputation:
I am not getting any response from server with following code ,I am getting token error '<' i have tried all
$(document).ready(function() {
$.ajax({
url:"url",
dataType: 'json',
success: function(output) {
var asd = JSON.stringify(output)
var i = $.parseJSON(asd);
for(var j=0;j<i.length;j++) {
$('#one').append('<p><div>TITLE   : <a href='+i[j].links+'>'+i[j].Title+'</a><br>SOURCE : '+i[j].Source+'<br>CATEGORY : '+i[j].Category+'<hr></p></div>');
//$('#one').append('<p><div style="background-color:#ccc"><span style="font-weight:bold" >SOURCE</span> : '+i[j].Source+'<p>');
//$('#one').append('<p><div style="background-color:#ccc" onclick="get"><span style="font-weight:bold" >CATEGORY</span> : '+i[j].Category+'<hr><p></div>');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
alert(thrownError);
}
});
});
Upvotes: 3
Views: 169
Reputation: 783
There is no need to call JSON.stringify() and parseJSON(). If output is an array, you can use directly output[0].Source and output[0].Category
$.ajax({
url:"url",
dataType: 'json' ,
success:function(output) {
for(var j=0;j<output.length;j++) {
$('#one').append('<p><div>TITLE   : <a href='+output[j].links+'>'+output[j].Title+'</a><br>SOURCE : '+output[j].Source+'<br>CATEGORY : '+output[j].Category+'<hr></p></div>');
}
},
error:function(xhr,ajaxOptions,thrownError){
alert(xhr.statusText);
alert(thrownError);
}
});
Upvotes: 2