javascript - block consecutive $http request -


i working in angular project there have grid data , actions.

on clicking 1 of action in onclick function ajax request going server side once in life time process.

but when user consecutively click action button before first request's response came same call going server more once ends in error.

i have tried disable action button before ajax request though cant prevent multiple request. there method block second request?

my code is

$http({   method: 'post',   url: urls.api_url_serv + 'notification/read?token=' + token,   transformrequest: transformrequestasformpost,   withcredentials: false,   headers: {     'content-type': 'application/x-www-form-urlencoded'   },   data: {     notification_id: notification_id   } }).then(function(response) {   var data = response.data;   //some actions   }).catch(function(response) {   var status = response.status;    // actions  }); 


<span ng-class="{'disabled': read_disable}"> <i class="fa fa-envelope" ng-click="markasreadnotification(row.id)"></i> </span> 

you can idiomatic way example (using es6 syntax use this in simple way)

this.makerequest = () => {   if (!this.request) {     this.request = $http({       method: 'post',       url: urls.api_url_serv + 'notification/read?token=' + token,       transformrequest: transformrequestasformpost,       withcredentials: false,       headers: {         'content-type': 'application/x-www-form-urlencoded'       },       data: { notification_id }     });      this.request.success((data) => {       // if want let user request, after 1 finished       this.request = undefined     })   } } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -