I am tring to load my data.txt file's data in the position of "This is the first content". but it is giving me error/warning and not working.
Error: Access to XMLHttpRequest at 'file:///C:/Users/SA/Desktop/ajax/data.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. jquery-3.4.1.min.js:2 GET file:///C:/Users/SA/Desktop/ajax/data.txt net::ERR_FAILED send @ jquery-3.4.1.min.js:2 ajax @ jquery-3.4.1.min.js:2 k.fn.load @ jquery-3.4.1.min.js:2 (anonymous) @ trynew.html:16 dispatch @ jquery-3.4.1.min.js:2 v.handle @ jquery-3.4.1.min.js:2 jquery-3.4.1.min.js:2 XHR failed loading: GET "file:///C:/Users/SA/Desktop/ajax/data.txt".
index.html
<!DOCTYPE html>
<html>
<head>
<title>AJAX</title>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script >
$(document).ready(function()
{
$("#btn").click(function()
{
$("#test").load("data.txt", function(){
alert("this is the message for a moron");
});
});
});
</script>
</head>
<body>
<div>
<p id="test"> This is the first content </p>
</div>
<button id="btn">Click the button to change</button>
</body>
</html>
data.txt
<p>Hello this is the new text punk!</p>