2014-04-05 30 views
1

我有一些Restangular和獲取/放置元素的問題。 首先,如果我嘗試獲取一個元素,則會收到帶有交叉起點的錯誤。Restangular失敗並在嘗試GET/PUT時生成URL

Restangular.one('api/label-resource', 1).get().then(function(success) { 
    // Change some propertries 
    success.put(); 
} 

XMLHttpRequest cannot load http://localhost:3000/api/template/1. The request was redirected to 'http://localhost:3000/api/label-resource/1/', which is disallowed for cross-origin requests that require preflight. 

如果我嘗試用PUT失敗原因是試圖達到http://localhost/api/label-resource/1/1/

Restangular.oneUrl('api/label-resource/1/').get().then(function(success) { 
    // Change some properties 
    success.put(); 
} 

我的REST API的URL獲得它是Django的REST的框架。

回答

0

對於具有交起源,因爲我發現Restangular具有用於此方法中的缺少的斜線的第一個問題 -setRequestSuffix(「/」),但是這是全局設置它不僅對當前的請求。

關於生成錯誤url的第二個問題我發現我必須爲本地var分配響應,然後在它上面發出請求。 。 Restangular.oneUrl( 'API /標籤的資源/ 1 /')得到(),然後(函數(成功){ VAR標籤=成功;

// Change some properties 
label.text = "New text"; 
label.put(); 

}