-6
<!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.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
RAO HAMMAS
  • 61
  • 1
  • 2
  • 13

2 Answers2

1

According to your console output:

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.

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

Script47
  • 14,230
  • 4
  • 45
  • 66
1

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

Jaykumar Patil
  • 359
  • 4
  • 13