I have a json response in the form of data with format like this. It is part of the whole data released
I have made a script to read the data :
$(document).ready(function() {
$.getJSON('http://services.berthojoris.com/json/baca2.php', function(data) {
for(var i=0; i<data[0].actionDetails.length;i++){
document.write('Judul Halaman : '+ data[1].actionDetails[i].pageTitle+"<br>");
document.write('URL : '+ data[1].actionDetails[i].url+"<hr>");
}
});
});
But the data generated using getJSON only 1, 2 or 5 data. While there are actually a lot of results generated process.
How do I capture all of the data generated??
I just wanted to take the pageTitle and url data from the data.
At first glance, you are mixing data[0]
and data[1]
(it will display all action details from the first item in the data
array)
$(document).ready(function() {
$.getJSON('http://services.berthojoris.com/json/baca2.php', function(data) {
for(var i=0; i<data[0].actionDetails.length;i++){
document.write('Judul Halaman : '+ data[0].actionDetails[i].pageTitle+"<br>");
document.write('URL : '+ data[0].actionDetails[i].url+"<hr>");
}
});
});
If you want to display all action items in data
$(document).ready(function() {
$.getJSON('http://services.berthojoris.com/json/baca2.php', function(data) {
$.each(data, function(idx, item){
$.each(item.actionDetails, function(idx, actionDetail){
document.write('Judul Halaman : '+ actionDetail.pageTitle+"<br>");
document.write('URL : '+ actionDetail.url+"<hr>");
})
})
});
});
Also note, you may have to use $('body').append(string)
instead of document.write(string)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.