0

I am trying to load a html page in a div through .load() method.

<div id="randomDiv">

and then in Js function ( let say on click of a button ) trying this : $('#randomDiv').load('js/abc.html');

I have added "script src="js/jquery-1.8.2.min.js" " in the html file.

But i am getting this error : XMLHttpRequest cannot load file:////C:/code/js/abc.html Origin null is not allowed by Access-Control-Allow-Origin.

I am using Chrome.

Also i am getting the warning at page load for almost all js included "Resource interpreted as Script but transfered with MIME type text/plain".

What is going wrong ?

Thanks

Agrawal
  • 123
  • 12

2 Answers2

3

try to use

$('#randomDiv').load('js/abc.html');

This is a cross-domain request and is not permitted. Test from localhost instead of an external file

your abc.html should be inside localhost

Kanishka Panamaldeniya
  • 17,302
  • 31
  • 123
  • 193
  • I am using # only. What cross-domain request is not permitted , i didnt understand this.My default.html is at C:/code/default.html and the default.js containing the load code is at C:/code/js/default.js . – Agrawal Jan 15 '13 at 08:15
  • you are welcome , mark the answer as the correct one please , so the future users can easily find the correct solution :) – Kanishka Panamaldeniya Jan 15 '13 at 12:41
0

Your selector is wrong as already mentioned, but you're also trying to make an ajax request to a local file which is not permitted per default. You should run your page on a web server, but you could also switch file access on with chrome.exe --allow-file-access-from-files.

See this question for more info XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)

Community
  • 1
  • 1
Tetaxa
  • 4,375
  • 1
  • 19
  • 25