2014-02-12 35 views
1

我有一些jQuery的是獲取數據和執行的回調:

$(function(){ 
$.ajax({ 
    type: 'POST', 
    url: 'http://flash-cast-hrd.appspot.com/api/sonar/sync', 
    data: { 
     source: 5, 
     auth: 'JXEI....DHA2J' 
    }, 
    success: displayData 
}); 
}); 

我想從我的角度控制器,在那裏我有一個方法上提出同樣的要求範圍。

​​

然後調用它的觀點:

<div ng-init="init()"></div> 

當我加載頁面我在控制檯得到一個錯誤:

OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync 405 (Method Not Allowed) angular.js:8021 
OPTIONS http://flash-cast-hrd.appspot.com/api/sonar/sync No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. angular.js:8021 
XMLHttpRequest cannot load http://flash-cast-hrd.appspot.com/api/sonar/sync. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8000' is therefore not allowed access. :8000/routes:1 
Error is: 

我怎樣才能讓角$ HTTP。發佈要求工作?

+0

可能重複此問題http://stackoverflow.com/questions/16661032/http-get-is-not-allowed-by-access-control-allow-origin-but-ajax-is – Vinoth

+0

XMLHttpRequest錯誤可以解決通過在服務器上部署,在部署到服務器後嘗試運行,希望它能工作 – ajitksharma

+0

訪問控制 - 允許來源 – Prashobh

回答

0

問題是因爲跨域訪問,您可以通過在您的服務器上設置proxypass來解決問題,並且您的請求還需要包含Access-Control-Allow-header。