Javascript 对于未命中GET api的每个循环
这是我的药品清单Javascript 对于未命中GET api的每个循环,javascript,angularjs,for-loop,Javascript,Angularjs,For Loop,这是我的药品清单 $scope.initStarttoGetDrugs = function () { $http({ url: '/MedicineParserApp/getmedicinefromdb', method: "GET", }).success(function(response){ $rootScope.MedicinneName = response;
$scope.initStarttoGetDrugs = function () {
$http({
url: '/MedicineParserApp/getmedicinefromdb',
method: "GET",
}).success(function(response){
$rootScope.MedicinneName = response;
var medlength = response.length;
response.forEach(function(listItem, index){
$scope.keyup(listItem) // here i want to hit the api
});
});
};
$scope.initStarttoGetDrugs();
在控制台上,它将访问url,但不会访问api,也不会给出响应
$scope.keyup = function (data) {
$http({
url: 'https://www.example.com/medicineinfo/search?q='+data,
method: "GET",
}).success(function(response){
console.log(response)
$scope.results = response.data;
$rootScope.vars = $scope.results
console.log($rootScope.vars);
for(var i = 0; i <= 3; i++) {
$scope.onclickfetchinfo($scope.results[i].slug, $scope.results[i].id)
}
});
};
$scope.keyup=函数(数据){
$http({
网址:'https://www.example.com/medicineinfo/search?q="数据,,
方法:“获取”,
}).成功(功能(响应){
console.log(响应)
$scope.results=response.data;
$rootScope.vars=$scope.results
log($rootScope.vars);
对于(var i=0;i这是因为您的请求已被缓存。请始终向服务器发送新的url。
url:““+新日期().getTime()