我想用$ HTTP來發送Ajax請求,我寫這樣的代碼,但我得到的錯誤
Error: $http is not defined
我把這個代碼在運行
app.run(['$rootScope','$location','$timeout','$http', function ($rootScope,$location,$timeout,$http) {
$rootScope.getMember = function(val){
var persons = $rootScope.selectPerson;
if(persons.length == 0)
persons = null;
return $http({
url: 'projectTask/GetMemberForFreeTask',
method: "POST",
data: $.param({'searchStr':val,'selectedPerson': persons}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function(response) {
for(var i = 0; i<response.data.length; i++){
response.data[i]['first_name'] = response.data[i]['first_name']+' '+ response.data[i]['last_name']
}
$rootScope.states = response.data;
return response.data
}
);
}
}])
我不清楚你想do..please精心更多 –
@pankajparkar我想在運行 –
發送Ajax請求,爲什麼你想在運行程序段正是 –