2015-09-15 63 views
0

我正在使用jQuery來獲取跨域數據,但我得到這個錯誤如何使用jQuery獲取跨域數據?獲取錯誤

SyntaxError:missing;聲明 之前這裏是我的代碼

<script> 
    (function($) { 
    var url = '//heald-chiampa.tributes.com/funeral_homes/search?json=1'; 
    $.ajax({ 
      type: 'GET', 
     url: url, 
     async: false, 
     contentType: "application/json", 
     dataType: 'json', 
       success: function(json) { 
     alert(json); 
    }, 
    error: function(e) { 
     console.log(e.message); 
    } 

    }); 
    })(jQuery); 
</script> 

當我改變數據類型從JSONP成JSON然後我收到此錯誤 跨來源請求阻止:同源策略不允許在http://heald-chiampa.tributes.com/funeral_homes/search?json=1讀取遠程資源。 (原因:缺少CORS頭'Access-Control-Allow-Origin')。

回答

0

他簡單的答案是你不能從jquery訪問另一個域服務。閱讀關於CORS here

0

服務器獲取請求應該輸出這個頭:

Access-Control-Allow-Origin: http://www.yourdomain.com