javascript - angular js : How to call multiple asynchronous http request one after another and store the respone for later use? -
please please help:( (disapointed)
i have table in mysql database stores avalabe book times;
in site , there buttons user can nail , related avalable book times , can see in image attached .
every time user hits arrow left/right , trigger mill function , i'll info contains avalabe books related day ,everything works fine far.
problem: when user first comes site , i'll current day , i'll show avalable book times related day(today) , , when user hits arrow left/right , i'll avalabe books related 3 days later today. works fine too.
but slow.
i want when user comes site , info related today until 2 month later .
but want show today's(and next day , , next 2day) avalabe books. when user clicks on arrow left/right , wont have phone call http request , forcefulness user wait until info avalabe see.
is there way define asynch http requests , store callback success info , dont utilize until user hits special key(in case arrow left/right)???
here http request function in mill :
app.factory('showbookingfacdrprofile',function($http){ return{ showbooking:function(scope){ $http.post("partials/search-drprofile/show_available_books.php",{today,nextday,next2day})// simplicized object send here .success(function(msg){ scope.booking=msg;; //here want : then.post('sameurl',{next3day,next4day,next5day}) // want repeat until 2 month later today then.post('sameurl',{next6day,next7day,next8day}) } } });
related controller:
$scope.hitarrow = function(current) { $scope.pager = current; searchfac.search($scope); };
noting special in controller
i know can utilize promises ! , how store them ? ?how utilize them later ?
i can't store them in new scope.booking , e.g : scope.booking2 , because can't utilize them :(
i cannot utilize cache because maybe every min avalabe books has changed :(
this view:
<div class='col-xs-4'> <table class='table table-responsive' > <tr data-ng-repeat='v in booking |filter:{month:date.next2month} |filter:{day:date.next2day}'> <td><a>{{v.hour}}</a></td> </tr> </table> </div> <div class='col-xs-4'> <table class='table table-responsive' > <tr data-ng-repeat='v in booking |filter:{month:date.nextmonth} |filter:{day:date.nextday}'> <td><a>{{v.hour}}</a></td> </tr> </table> </div> <div class='col-xs-4'> <table class='table table-responsive' > <tr data-ng-repeat='v in booking |filter:{month:date.today} |filter:{day:date.today}'> <td><a>{{v.hour}}</a></td> </tr> </table> </div>
note i've seen approach in site click
please see, , nail arrows you'll see how fast new avalable book times comes view
if $scope. booking array, have append contents of http responses (array.push(object)).
javascript angularjs
No comments:
Post a Comment