Getting 404 error on POST. Angular.js

11,058

It looks like it was something on the server side configuration. We had set the Access-Control-Allow-Origin to *. According to the answer below, Chrome no longer supports that.

Original (wrong):

header("Access-Control-Allow-Headers: *");

Corrected:

header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

For more information check out this post. https://stackoverflow.com/a/18192705/3010896

Share:
11,058
justin.c
Author by

justin.c

Updated on June 04, 2022

Comments

  • justin.c
    justin.c about 2 years

    new to Angular and javascript. I am using Angular to connect to a service on a different server. I am able to get data just fine, but when I am trying to post, I get a 404. I tried to follow the Angular documentation as closely as possible. What am I doing wrong?

    PS. I have sniffed my traffic, and I noticed that my POST hex was completely empty. I am stumped.

    EDIT: Heres the error(s) I am getting in the console.
    
    OPTIONS http://url 404 (Not Found) angular.js:7997<br>
    OPTIONS http://url Invalid HTTP status code 404 angular.js:7997<br>
    XMLHttpRequest cannot load http://url. Invalid HTTP status code 404
    
    
    
    app.controller('SendController', ['$scope', 'Request', function($scope, Request) {
    
        $scope.request = {
            // test data here
        };
    
        $scope.send = function() {
            Request.save($scope.request);
        };
    }]);
    
    
    app.factory('Request', ['$resource',
        function($resource) {
            return $resource(url);
        }]);