简体   繁体   English

将html页面加载到页面上的div中

[英]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 : 我试图将一个单独的html文件加载到站点上已经存在的div中,并且出现以下错误:

XMLHttpRequest cannot load MyFile Origin null is not allowed by Access-Control-Allow-Origin. XMLHttpRequest无法加载MyFile Origin-Access-Control-Allow-Origin不允许使用null。 filename.html:1 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. 只能将来自同一域的URL嵌入div中。 Try hosting a local webserver and try loading the file from there. 尝试托管本地Web服务器,然后尝试从那里加载文件。

$("#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 在目标站点上设置Access-Control-Allow-Origin标头
  • use an iframe 使用iframe
  • use a proxy on your server to proxy the content from the other site. 使用服务器上的代理来代理其他站点的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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