I am trying to show the post from different json urls but cant find how to do that with php and javascript, I try it through php but only from one url, I don't how to load more data from different json urls. my code is below for on json url.
$json_link = "http://www.pinkvilla.com/photo-gallery-feed-page";
$json = file_get_contents($json_link);
$obj = json_decode($json, true);
$feed_item_count = count($obj['nodes']);
for($x=0; $x<$feed_item_count; $x++){
$title = $obj['nodes'][$x]['node']['title'];
echo($title)."<br>";
}
using script this for other pages
function getAllData(page) {
return $.getJSON('http://www.pinkvilla.com/photo-gallery-feed-page/page/' + (page || 1), function(data) {});
$.ajax({
url:"http://www.pinkvilla.com/photo-gallery-feed-page/page/" + (page || 1),
method:'get',
dataType:'JSON'
}).then(function(response){
console.log(response);
});
}
getAllData(1).then(function(orders) {});
but this script giving me error " Access to XMLHttpRequest at '...' from origin '...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. "
this is the url where I am getting the json data
http://www.pinkvilla.com/photo-gallery-feed-page
Now I have to load the data from different link when I scroll to last post from this upper link then want to load the posts from other link like from
http://www.pinkvilla.com/photo-gallery-feed-page/page/1
after this links last post shows after that
http://www.pinkvilla.com/photo-gallery-feed-page/page/2
this link post will shown on scroll.
Please help me with this.
What I have tried:
function getAllData(page) {
return $.ajax({
url:"http://localhost/php/" + (page || 1) + ".json" ,
method:'get',
dataType:'JSON'
}).then(function(response){
if (page && response.nodes.length == 250) {
return getAllData(page + 1)
.then(function (more) {
return response.nodes.concat(more)
})
}
console.log(response.nodes);
for(i = 0; i < response.nodes.length; i++) {
data += '<div class="wf-box"><a href="' + response.nodes[i].node.title + '" target="_blank"><img src="' + 'https://www.pinkvilla.com' +response.nodes[i].node.field_photo_image_section + '"></a><div class="content"><div class="title"><a href=""></a></div><a class="options"></a></div></div>';
}
document.getElementsByClassName("wf-container")[0].innerHTML = data;
});
}
getAllData(1).then(function(nodes) {
});