Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda