我正在嘗試使用我設計的其餘api爲我的應用程序進行登錄。如果我強迫完整的URL與用戶和通它的工作原理好嗎:
http://www.myexample.com/ACTION/USER/PASSWORD/
但我需要從我的表單的輸入域取數據。這是函數的代碼在我的控制器:
$scope.authenticar = function(selectedUs, selectedPw){
$scope.remoteData = null;
//alert(selectedUs);
dataService.getData(function(data) {
$scope.resultAPI = data;
$scope.username=$scope.resultAPI.username;
$scope.id_user=$scope.resultAPI.id_user;
$scope.isauthenticated=$scope.resultAPI.isauthenticated;
$scope.user_role=$scope.resultAPI.user_role;
$scope.complete_name=$scope.resultAPI.complete_name;
});
}
這是服務代碼:
.service('dataService', function($http) {
delete $http.defaults.headers.common['X-Requested-With'];
this.getData = function(callback) {
var myparams = {a: '', u: '', p: ''};
myparams.a = 'ZW50cmFy';
myparams.u = 'anRk';
myparams.p = '899960d8dd39b29e790845912cb35d96';
$http({
method: 'GET',
url: 'http://www.adagal.net/api_adagal/api.php',
withCredentials: false,
params: myparams,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).success(function(data, status, header, config){
// With the data succesfully returned, call our callback
callback(data);
}).error(function(){
$scope.remoteData = null;
return "Connection Error";
});
}
});
我試圖通過一切方式,我怎麼能得到的URL這種方式?
目前還不清楚你想在這裏做什麼。這聽起來好像你想傳遞一個動態字符串到$ http哈希url參數?真的嗎?這種情況下你的問題是什麼? –
確實,我正嘗試將一個動態字符串傳遞給$ http。我的問題是,如果我將參數傳遞給函數,如下所示: this.getData = function(callback,p,u)它不工作,不傳遞數據。 –