Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs Service performing a POST request randomly gets cancelled

Tags:

http

angularjs

I have a service that makes a simple POST:

saveVersion: function(styleGuideId, data){
    return $http({method: 'post', url: '/style_guides/' + styleGuideId + '/new_version', data: data}).then(function(project){
      console.log('request completed')
    });
  },

In the console, if I fire this request, it works fine.

But when I click a button in my ui that makes this request, I see on my server the request gets completed with a 200 but on the client side the browser says it is cancelled.

enter image description here

The extra GET is also a mystery. In the console, I trigger the request like this:

angular.element(document.body).injector().get('StyleGuides').saveVersion(sg_id, data)
//sg_id and data are local variables that I got like this:
sg_id = angular.element($0).scope().project.style_guide_id
like image 207
dylanjha Avatar asked Jul 29 '26 06:07

dylanjha


1 Answers

Just figured it out. Stupid Mistake

The button that triggers the save looked like this:

<a href="javacript://" ng-click="saveVersion()">Save</a>

See the typo? changing javacript:// to javascript:// fixed the issue.

like image 166
dylanjha Avatar answered Jul 30 '26 22:07

dylanjha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!