I am trying to load a separate html file into an already existing div on a site and i am getting the following error :
XMLHttpRequest cannot load MyFile Origin null is not allowed by Access-Control-Allow-Origin. filename.html:1
I am using the load function as follows :
$("#wrapper").load('filename.html');
-
you are trying to call a file from different domain I believe Can you check thatSatya– Satya2013年05月27日 08:16:04 +00:00Commented May 27, 2013 at 8:16
-
no i am not trying to call the file from a different domainstark– stark2013年05月27日 08:55:33 +00:00Commented May 27, 2013 at 8:55
2 Answers 2
You can't load content from another domain like that - the Same Origin Policy prevents it for security reasons. You need to do one of these things:
- set up the
Access-Control-Allow-Originheader on the target site - use an
iframe - use a proxy on your server to proxy the content from the other site.
answered May 27, 2013 at 8:16
RichieHindle
284k49 gold badges367 silver badges408 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
stark
by the target site do you mean the site which i want to load into the div or the one containing the div ?
RichieHindle
@stark: The one you're trying to load.
stark
Also would this be fixed if i run the file on a xampp server locally ?
RichieHindle
@stark: Yes - if both pages are served from the same domain, you won't see this problem.
Only URLs from the same domain is allowed to be embedded inside a div. Try hosting a local webserver and try loading the file from there.
$("#wrapper").load('./filename.html');
answered May 27, 2013 at 8:16
ATOzTOA
36.1k23 gold badges101 silver badges119 bronze badges
Comments
default