Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

356
Views
is it possible to prevent the display of an Ajax 404 error in the browser?

I'm attempting to load json files as soon as the page loads. Those json files are contained within a folder, and they serve as the foundation around which the programme is constructed (each json file represents a page). The issue is that I want the script to be able to handle a random amount of json files, which is not possible.

For the time being, I have the following recursive code that does precisely what I need it to do: it loads each page and, in the event of an error, it runs the application's startup procedure. I'm having trouble since my browser is returning a 404 error, which is understandable given the situation. I'm wondering whether there is a method to catch the 404 error (which signals that there are no more json files to be loaded) without the error being displayed in the browser.

This link doesn't help (Catch a 404 error for XHR)


$(document).ready(function() {
    let pageArray = [];
    loadPages(1, pageArray);

    function loadPages(nb, array) {
        $.ajax({
            url: 'configuration/pages/page' + nb + '.json',
            dataType: 'json',
            error: function() {
                initialize(array);
            },
            success: function(data) {
                array.push(data);
                loadPages(nb + 1, array);
            }
        });
    }

    function initialize(pages) {
        console.log(pages);
    }
});```
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!