0

i make a script which get data and append it into html table in JavaScript The problem is that i have multiple page url like https://myAPI?param=2&perPage=100&page=1(page2,page3 etc) and i have pages like this amount 300 pages

How i can get data from all pages of my API?

here my code, the problem is that only small amount of urls work, if i paste more urls, its not work

var urls = ['https://myAPI?param=2&perPage=100&page=1', 'https://myAPI?param=2&perPage=100&page=2', 'https://myAPI?param=2&perPage=100&page=3',
'https://myAPI?param=2&perPage=100&page=4',
'https://myAPI?param=2&perPage=100&page=5',
'https://myAPI?param=2&perPage=100&page=6',
]


$(document).ready(function(){
$.getJSON(urls, function(data){
    var product_data = '';
$.each(data.items, function (i, items) {
    

        product_data += '<tr>';
        product_data += '<td>'+ items.gimaId + '</td>';
        product_data += '<td>'+ items.id + '</td>';
        product_data += '<td><a target="_blank" href="url/' + items.code + '">' + items.title + '</a> </td>';
        product_data += '<td>'+ items.categoryCodes.code + '</br>'  + items.categoryCodes.name +'</td>';
        product_data += '<td>'+ items.vendorCode + '</td>';

        product_data += '<td>'+ items.price.value + '</td>';
        product_data += '<td>'+ items.stock.qty + '</td>';
        product_data += '<td><a target = "_blank" href="url' + items.catalogImageId + "/" + '">' + items.catalogImageId + '</a></td>';
        product_data += '<td>'+ items.description.content + '</td>';
        product_data += '<td>'+ items.active + '</td>';
        product_data += '<td>'+ items.storageAddress + '</td>';
        product_data += '</tr>';
});

    

$('#showData').append(product_data);

});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="showData" class="tavle">
<tr>

    <th>id</th>
    <th>id</th>
    <th>id</th>
    <th>id</th>
    <th>id</th>
    <th>id</th>
    <th>id</th>
    
  
    
</tr>
    </table>

1 Answer 1

1

You need to loop over the pages using a for loop. Example:

var pages = 0;
var url = 'https://myAPI?param=2&perPage=100&page=';
for(var i = 0; pages < 300; i++) {
    newUrl = url + i;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.