0

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');
Ram
145k16 gold badges174 silver badges201 bronze badges
asked May 27, 2013 at 8:14
2
  • you are trying to call a file from different domain I believe Can you check that Commented May 27, 2013 at 8:16
  • no i am not trying to call the file from a different domain Commented May 27, 2013 at 8:55

2 Answers 2

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-Origin header 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
Sign up to request clarification or add additional context in comments.

4 Comments

by the target site do you mean the site which i want to load into the div or the one containing the div ?
@stark: The one you're trying to load.
Also would this be fixed if i run the file on a xampp server locally ?
@stark: Yes - if both pages are served from the same domain, you won't see this problem.
2

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.