简体   繁体   English

请求的资源上不存在“ Access-Control-Allow-Origin”标头

[英]No 'Access-Control-Allow-Origin' header is present on the requested resource

On a custom wordpress page I click on my links and I get this error Also the links don't open. 在自定义的wordpress页面上,我单击我的链接,但出现此错误,而且链接也没有打开。 Clicking doesn't do anything. 单击不执行任何操作。

XMLHttpRequest cannot load mysite/. XMLHttpRequest无法加载mysite /。 No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin 'mysite' is therefore not allowed access. 因此,不允许访问来源“ mysite”。

Where mysite is the url of my website. mysite是我的网站的网址。

Is anyone familiar with this issue? 有人熟悉这个问题吗?

The page where the error occurs is: http://wouterleduc.com/publications/ 发生错误的页面是: http : //wouterleduc.com/publications/

And I'm using this code on my page template: ` 而且我在页面模板上使用了以下代码:

<?php if (have_posts()) : the_post(); ?>

    <h3 class="h3_serie_overzicht"><?php the_title(); ?><span id="<?php the_title();?>">&nbsp;&nbsp;&nbsp;</span><a href"#" class="serie_overzicht_info" id="<?php the_title(); ?>">Show text</a></h3>

    <div class="serie_overzicht_info_pane"><?php echo the_content(); ?></div>

<div id="serie-overzicht-thumbs">
    <?php $attachments = new Attachments( 'attachments' ); ?>
    <?php if( $attachments->exist() ) : ?>
      <div class="serie_overzicht_row">
        <?php while( $attachments->get() ) : ?>
          <div class="serie_foto">
           <a target="_blank" href="<?php echo $attachments->field( 'link' ); ?>" title="<?php echo $attachments->field( 'title' ); ?>"><img src="<?php echo $attachments->src( 'medium' ); ?>"" title="<?php echo $attachments->field( 'title' ); ?>" alt="<?php echo $attachments->field( 'title' ); ?>" /><br /><span><?php echo $attachments->field( 'title' ); ?></span></a>
          </div>
        <?php endwhile; ?>
      </div>
    <?php endif; ?>

` `

I use the attachments pluging from Jonathan Christopher to display images. 我使用乔纳森·克里斯托弗(Jonathan Christopher)插入的附件来显示图像。 I use fancybox in my theme but it should only effect the links with a rel tag. 我在主题中使用了fancybox,但它仅会影响带有rel标签的链接。

The problem is you are missing the cross-origin request header. 问题是您缺少跨域请求标头。 I checked as follows 我检查如下

curl -I http://wouterleduc.com/publications/

HTTP/1.1 200 OK
Date: Mon, 29 Sep 2014 19:40:11 GMT
Server: Apache/2
X-Powered-By: PHP/5.4.32
X-Pingback: http://wouterleduc.com/xmlrpc.php
Link: <http://wouterleduc.com/?p=2358>; rel=shortlink
Vary: User-Agent
Content-Type: text/html; charset=UTF-8

Add the following line to your php code 将以下行添加到您的php代码中

<?php
 header("Access-Control-Allow-Origin: http://mysite");
?>

You can use curl to test it. 您可以使用curl进行测试。 If all is well then your XmlHttpRequest should work. 如果一切顺利,那么您的XmlHttpRequest应该可以工作。 There are some security implications. 有一些安全隐患。 I would have a look at http://enable-cors.org to find out more. 我将在http://enable-cors.org上查找更多信息。

暂无
暂无

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

相关问题 错误:请求的资源上没有“Access-Control-Allow-Origin”标头 - Error: No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“ Access-Control-Allow-Origin”标头 - No ‘Access-Control-Allow-Origin’ header is present on the requested resource PHP:请求的资源上不存在“Access-Control-Allow-Origin”标头 - PHP : No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源 Symfony 上不存在“访问控制允许来源”header - No 'Access-Control-Allow-Origin' header is present on the requested resource Symfony Laravel 7 - 没有“访问控制允许来源” header 存在于请求的资源上 - Laravel 7 - No 'Access-Control-Allow-Origin' header is present on the requested resource ''Access-Control-Allow-Origin' header 出现在请求的资源上 - ''Access-Control-Allow-Origin' header is present on the requested resource WordPress 请求的资源上不存在“Access-Control-Allow-Origin”标头 - WordPress No 'Access-Control-Allow-Origin' header is present on the requested resource Phonegap请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许原点&#39;null&#39;访问 - Phonegap No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access 没有用Php标头解决的请求资源上没有&#39;Access-Control-Allow-Origin&#39;标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource not solved with Php header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM