Retry failed ajax request in vuejs

424 views Asked by At

What's the best way to retry failed AJAX request in VueJS ?

bulkDecline(requests, decliner) {
  requests = _.map(requests, 'id');
  return Vue.http.post(`${baseUrl}/api/decline/${decliner}/bulk-decline`, requests)
    .then(
      (response) => {
        Notification({
          title: 'Success!',
          message: response.data.message,
          type: 'success'
        });
        return response;
      }, 
      (response) => {
        this.bulkDecline(requests, decliner);
      }
    );
}

But it seems like its not working.

1

There are 1 answers

0
darryn.ten On

Are you doing this within a single-file component?

If so, have you tried using

this.$http.post

instead of Vue.http.post?

You may also have some luck if you send through your requests in an object like { data: requests } or similar.

return this.$http.post(`${baseUrl}/api/decline/${decliner}/bulk-decline`, { data: requests })