There is always a problem in the project: after entering keywords in the search bar (see Figure 1), according to the established business logic, it should be that after the server receives the request, it will first return the first 7 pieces of data in the query. When the client appears to load up, continue to search for the other 7 pieces of data. But the actual situation is uncertain. On the server console (see Figure 2), you can see begno until 126, which is equivalent to the client requesting 127 times to the server, which is an unbearable result.
Figure 1 Client search bar
Figure 2 Server console
It can be concluded that there is a problem with the client's business logic. Return to the client, view the source code logic, and modify it as follows:
Controller
$scope.medsearchMore = function() { console.log("Pull-up load......" + isfinished); if (isfinished == 0) { begin += pcnt; var data = { "begno" : begin, // Start number "pagenum" : pagenum, // Return number per page "searchby": searchby }; if (searchType == 1) { data.classid = searchKey; console.log(data.classid); //-------1 appCallServer($http, "9002", data, function(data) { console.log("Drop down to refresh the query result rootScope.med:" + JSON.stringify(data.data)); for (var i = 0; i < data.pcnt; i++) { $rootScope.med.push(data.data[i]); } // Update status is finished is finished with data.isfinished; // Drug query if(isfinished == '1'){ $scope.noMore = true; }else{ $scope.noMore = false; } pcnt = data.pcnt; }, function(data) { // Drug query $scope.noMore = true; $ionicLoading.show({ template: data.ertext }); $timeout(function() { $ionicLoading.hide(); }, 1200); }); } } else { // The drug has been queryed $scope.noMore = true; } $timeout(function() { $scope.$broadcast('scroll.infiniteScrollComplete'); }, 1200); };view
<!-- When the user reaches the footer or near the footer, the ion-infinite-scroll directive allows you to call a function. When the user scrolls beyond the content at the bottom, the on-infinite specified will be triggered-> <!--When there is no more data loading, you can use a simple method to prevent infinite scrolling, that is, the angular ng-if directive-> <!--Set the initial value of noMore to true, and the first time you click on the classification query, no pull-down loading operation--> <ion-infinite-scroll on-infinite="medsearchMore()" distance="0.01%" icon="ion-loading-c"></ion-infinite-scroll> <div ng-if="noMore" align="center"><p>No more drugs</p></div>
After the above modifications, unnecessary requests can be avoided.