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>