Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
PHP
$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
JavaScript
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:

JavaScript
function getAllData(page) {
    return $.ajax({
        url:"http://localhost/php/" + (page || 1) + ".json" ,
        method:'get',
        dataType:'JSON'
    }).then(function(response){
        //console.log(response);        
        if (page && response.nodes.length == 250) {
            return getAllData(page + 1)
            .then(function (more) {
                return response.nodes.concat(more)
            })
        }
        
        console.log(response.nodes);
        //return 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) {
});
Posted
Updated 23-Nov-20 19:03pm
v2

1 solution

Quote:
No 'Access-Control-Allow-Origin' header is present on the requested resource
The URL you are trying to load is not configured to allow requests from your script.

If you control the remote site, you will need to modify the site's configuration:
Cross-Origin Resource Sharing (CORS) - HTTP | MDN[^]

If not, you will need to contact the owners to request that they modify the configuration.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900