The following works when I run off my web servers, however when I run off my local desktop (no local web server) I encounter an error.
below are the three files:
index.html
<html>
<head>
<script src="jquery-1.11.1.js"></script>
</head>
<body>
<span>First or Second?</span> <input type="text" id="var"> <button type="button" onclick="load()">AJAX it</button>
<div id="container">
</div>
</body>
<script type="text/javascript">
function load()
{
input = $('#var').val() + '.html';
input = input.toLowerCase();
if (input == 'first.html')
{
$( "#container" ).load( "first.html" );
} else if (input =='second.html') {
$( "#container" ).load( "second.html" );
} else {
$('#container').html('invalid input');
}
}
</script>
</html>
first.html
first
second.html
second
However, when making either of the .load() calls, I get the following error:
XMLHttpRequest cannot load file:///C:/Users/XXXX/Desktop/XXXX/test/first.html. Received an invalid response. Origin 'null' is therefore not allowed access.
Out of curiosity, why does this not work? The error message looks similar to some CORS errors. In fact, searching for more information to this leads to nothing but the slightly similar (but not identical) CORS error message when making a AJAX request to a different domain.