2014-09-29 30 views
0

在自定義wordpress頁面上,我點擊我的鏈接,出現此錯誤 此外鏈接無法打開。點擊不會執行任何操作。沒有'Access-Control-Allow-Origin'標題出現在請求的資源上

XMLHttpRequest無法加載mysite /。請求的資源上沒有「Access-Control-Allow-Origin」標題。因此不允許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();?>">&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; ?> 

`

我用的附件喬納森克里斯托弗pluging來顯示圖像。我在我的主題中使用fancybox,但它應該隻影響與rel標籤的鏈接。

回答

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"); 
?> 

您可以使用捲曲來測試它。如果一切正常,那麼你的XmlHttpRequest應該可以工作。有一些安全影響。我想看看http://enable-cors.org瞭解更多。

+0

嘿Snow6boy,謝謝你的回答。我已經添加了你在我的index.php中建議的php代碼,這是爲wordpress組裝所有需要的代碼的文件,但這仍然會觸發相同的錯誤。 我很困惑的是,我不想在這裏做一些難題。只需輸出一個錨標籤。純html。 因此,我認爲問題是用腳本或其他東西,但我卡在什麼是造成它 – ragoutje 2014-10-02 17:33:27

相關問題