在自定义wordpress页面上,我点击我的链接,我收到此错误 链接也没有打开。点击没有做任何事情。
XMLHttpRequest无法加载mysite /。 No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' mysite'因此不允许访问。
mysite是我网站的网址。
是否有人熟悉此问题?
发生错误的页面是:http://wouterleduc.com/publications/
我在页面模板上使用此代码: `
<?php if (have_posts()) : the_post(); ?>
<h3 class="h3_serie_overzicht"><?php the_title(); ?><span id="<?php the_title();?>"> </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; ?>
`
我使用Jonathan Christopher的附件来显示图像。我在我的主题中使用了fancybox,但它只应该使用rel标签来影响链接。
答案 0 :(得分:0)
问题是您缺少跨源请求标头。我检查如下
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
将以下行添加到您的PHP代码
<?php
header("Access-Control-Allow-Origin: http://mysite");
?>
您可以使用curl进行测试。如果一切顺利,那么你的XmlHttpRequest应该可行。有一些安全隐患。我想看看http://enable-cors.org以了解更多信息。