Sharepoint API Query fetching runs 3 times..?

45 viewshtmljavascriptjquerysharepoint
0

I have been facing this issue whereby my sharepoint api is fetching more than once. The function is only being called once BUT it fetches more than once..? Which causes some issue for the displays.

Note I have tried fetching it normally from the dev tools it returns the same.. basically fetching 3 times.

function fetchData(url, type, siteExist) {
     console.log("Fetching Data: "+ url ); // ONLY RUNS ONCE. 
     let timestamp = new Date().getTime();
     let apiUrl = url + "&timestamp=" + timestamp;
     
     fetch(apiUrl, {
         method: "GET",
         headers: {
             "Accept": "application/json; odata=verbose"
         }
     })
     .then(response => {
         if (!response.ok) {
             throw new Error(`HTTP error! Status: ${response.status}`);
         }
         return response.json();
     })
     .then(data => {
          if (type === 'eFile'){
             eFileResponse = [];
             if (data.d.query.PrimaryQueryResult.RelevantResults != null){
                 let totalPages = Math.ceil(data.d.query.PrimaryQueryResult.RelevantResults.TotalRowsIncludingDuplicates / 10);
                 console.log("Total pages: "+ totalPages);
                 if(totalPages > 0){
                     totalResults = data.d.query.PrimaryQueryResult.RelevantResults.TotalRows;
                     processResultsAndRenderCards(data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results, type);
                 }
             } 
         }
     })
     .catch(error => {
         console.error('Error:', error);
     });
}