Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

244
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda