<!DOCTYPE html>
<html>
<head>
<script src="jquery-2.1.4.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("rao.txt");
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
i want to change the content of div1 with some text or some other webpage without reloading the default page.
I get the following error message in the console:
XMLHttpRequest cannot load file:///C:/Users/hamma/Desktop/rao.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Copy the file "rao.txt" into your project folder. Setup a localserver. Use wamp/xamp for setting localserver. Access the file like
http://localhost/project_folder/path_to_rao.txt
According to your console output:
That means that you are trying to run the file without a server i.e.
file:///[...]
and for security reasons you can't run AJAX requests like that.You need to setup a server and run the page through that to send requests.
More Help
If you are using Chrome, try this.
Reading Material
Same-Origin-Policy
CORS