2016-03-08 27 views
0

在Magento我已經使用的,而不是產品圖片視頻發出fething數據,這是一個marketplace.there在前端型四用戶的 1.賣方 2.企業 3.業務代理 4.網站的客戶Magento的跨域用ajax從其他領域

商務代理 - >代理業務提供所有賣家的產品給別人的網站,如果通過其他網站購買,他將得到佣金,所以我給予和嵌入式代碼業務代理0,使他們能夠實現這個給別人網站但是當我試圖從其他域打ajax時,它會顯示跨域錯誤。

Cross-Origin Request Blocked: 
The Same Origin Policy disallows reading the remote resource at http://shopahol.com/demo/test.php?atoken=c0Q5QUk1VUgreEk9. 
(Reason: CORS header 'Access-Control-Allow-Origin' missing). 

要解決這個問題,我已嘗試添加訪問控制允許報頭到index.php

header('Access-Control-Allow-Origin: *'); 

,但問題沒有解決同樣的錯誤。然後我試圖把crossdomain.xml的在我的根文件夾

<!--l version="1.0--> 
<!--pan class="hiddenSpellError" pre=--> 
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> 
<cross-domain-policy> 
    <allow-access-from domain="*" /> 
</cross-domain-policy> 

它也沒有同樣的問題,任何人都可以有任何解決方案或我做錯了什麼。

這是我的代碼在其他網站上顯示視頻。 (簡單的HTML或PHP文件)

<!-- html starts --> 
     <div id="tevid" style="width:100%;"> 
      <video id="homevideo" width="100%" autoplay onended="run()"></video> 
     <div class="bg-background-new"> 
     <a href="" class="product-name-new" id="product-name">Product Name</a> 
     <div class="price-new" id="price"></div> 
     <a href="" id="button1" class="new-button">Buy Now</a> 
     </div> 
     </div> 
     <!-- javascript starts *Remove this script if you already included ajax jquery --> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js" > </script> 
     <script> 
      var video_count =0; 
      var videoPlayer = document.getElementById("homevideo"); 
      var allproduct = []; 

      function getvideos(){ 
       $(document).ready(function() { 
       $.ajax({ 
         url: "http://shopahol.com/demo/test.php?atoken=c0Q5QUk1VUgreEk9", 
         type: "GET", 
         dataType: "json", 
         success: function(data){ for(var i in data) { allproduct.push(data[i]); } run(); }, 
         error: function() { alert("Error During Process"); }  
       }); 
       }); 
      } 

      function run(){ 
      var nextVideo = allproduct[video_count].videourl; 
      var price = allproduct[video_count].pric; 
      var name = allproduct[video_count].name; 
      var url = allproduct[video_count].url; 
      videoPlayer.src = nextVideo; 
      videoPlayer.play(); 
      video_count++; 
      $("#price").html("$ "+price); 
      $("#product-name").html(name); 
      $("#product-name").attr("href", url) 
      $("#button1").attr("href", url) 
      if(allproduct.length == video_count){ video_count = 0; } 
      } 

     $(document).ready(function() { 
      getvideos() ; 
     }); 

     </script> 
     <!-- css starts --> 
     <style> 
     a.new-button { 
      background: red none repeat scroll 0 0; 
      border: medium none; 
      bottom: 0; 
      color: #fff; 
      cursor: pointer; 
      float: right; 
      font-weight: bold; 
      margin-top: 10px; 
      padding: 10px 20px; float: right; 
     } 
     .price-new { 
      color: #000; 
      display: block; 
      float: right; 
      line-height: 35px; 
      padding: 10px; 
     } 
     a.product-name-new { 
      color: #000; 
      display: inline-block; 
      float: right; 
      line-height: 35px; 
      margin: 10px 0; 
      position: relative; 
      right: 2px; 
      text-decoration: none; 
     } 
     .bg-background-new { 
      background: transparent none repeat scroll 0 0; 
      bottom: 65px !important; 
      display: block; 
      position: relative; 
      right: 0 !important; 
      width: 99%; 
     } 
     </style> 
的幫助

讚賞提前 感謝

回答

0

我的數字出來,所以我張貼的答案爲他人在相同的情況下 幫助我改變了我的AJAX功能

function getvideos(){ 
       $(document).ready(function() { 
       $.ajax({ 
         url: "http://shopahol.com/demo/test.php?atoken=WkFBU2F6bFdCNFU9", 
         type: "GET", 
         crossDomain: true, 
         dataType: "jsonp", 
         jsonpCallback: 'giveBacktome',       
         error: function() { console.log("Error During Process"); } 
       }); 
       }); 
      } 

它的工作原理