stark
stark

Reputation: 2256

loading an html page into a div on a page

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');

Upvotes: 0

Views: 144

Answers (2)

RichieHindle
RichieHindle

Reputation: 281875

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.

Upvotes: 2

ATOzTOA
ATOzTOA

Reputation: 36000

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');

Upvotes: 2

Related Questions