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

241
Visualizações
Why does $.ajax load the [base url + index.html] repetitively when requested relative url is not found

I have a situation where I load a file and move the content of that file to a placeholder in the HTML. The idea is visible in the code below which is the smallest snippet I could think of which mimics the issue.

When executing while the file in the webroot exists, there is no problem.

When executing while the file is non-existent, the webroot index.html starts loading repetitively while I just want it to execute the fail(). It should load nothing. The effect can be reproduced both in FF and in Chrome.

I must be missing something obvious. I used several ajax options (cache, timeout, headers, Crossdomain ), without effect.

My questions are : what causes this effect?
What am I doing wrong (again: I just want it to execute the fail() )?
What can I do to prevent this?

    <script>
        $(function () {
            Promise.all([LoadCUsermenu('CUsermenu.txt')]).then( ()=>{console.log('Promise fullfilled')} );
            console.log('Do the rest of the stuff')
        });

        function LoadCUsermenu(filename) {
            return $.ajax({
                url: filename
            }).done(function (response, responseStatus) {
                console.log('Usermenu present...Loading');
                $('#CUsermenu').html(response)
            }).fail(function (xhr, textStatus, errorThrown) {
                console.log('No Usermenu present...' + textStatus);
                $('#CUsermenu').html("<li>Nothing there</li>")
            })
        }
    </script>
<head>
</head>

<body>
    <ul id='CUsermenu'></ul>
    <div><p>Wil this be loaded repetetively???</p></div>
</body>

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