[英]Error: No 'Access-Control-Allow-Origin' header is present on the requested resource
[英]No 'Access-Control-Allow-Origin' header is present on the requested resource
在自定義的wordpress頁面上,我單擊我的鏈接,但出現此錯誤,而且鏈接也沒有打開。 單擊不執行任何操作。
XMLHttpRequest無法加載mysite /。 所請求的資源上沒有“ 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標簽的鏈接。
問題是您缺少跨域請求標頭。 我檢查如下
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上查找更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.