简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM