1

I have this POST request that can't go through. I have no problem making a GET or even PUT request, but the POST just appears as Cancelled in chrome dev tools.

$http({
       url: 'https://dev.myapp.com/classes/app/',
       method: 'POST',
       data: scope.original,//already tried to stringify and angular.json, etc. But it should work like this
       headers: {
           "X-app-Api-Key": scope.apiKeys['X-app-Api-Key'],
           "X-app-App-Id": scope.apiKeys['X-app-App-Id']
           }
       }).success(function(response) {
           console.log('ok');
       });

I can get it to work if I use jQUery's $.ajax:

 $.ajax({
     url: "https://dev.myapp.com/classes/app/",
     headers: {
            "X-app-Api-Key":"key",
            "X-app-App-Id":"key"
            }, 
     type: "POST",
     data: JSON.stringify({some: 'object'}),
     success: function(r) {console.log('ok');
               }
     });

But chrome just returns this when using angular's $ http:

XMLHttpRequest cannot load https://dev.myapp.com/classes/app/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://localhost:8000 is therefore not allowed access.

fmtoffolo
  • 361
  • 1
  • 3
  • 13
  • have you tried shorter version? `$http.post()` – GGio Jun 04 '14 at 21:03
  • Chrome unfortunately doesn't show you the response it received when the CORS headers are missing. Have you tried it in Firefox and looked at the response you received (and why it was lacking the CORS headers)? The error you see is telling you that for some reason, the response to your AngularJS POST request lacks the right CORS headers... – S.B. Jun 04 '14 at 21:17
  • But why is it working with jquery's ajax? In firefox I get the same as in chrome. Maybe angular is doing something extra that makes it fail? – fmtoffolo Jun 04 '14 at 21:33
  • just for fun, check this out... http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data – dbugger Jun 05 '14 at 02:17

0 Answers0