Latest

Tuesday, July 11, 2017

Angularjs laravel 5 posting form data using post method 404 page not found error. But get method works

Asked by: Balaji R


Using Angularjs laravel 5.1 posting form data using post method 404 error comes but get method works fine

controller

`(function (ng, app) { app.controller('app.promocodeCtrl', function($scope,$http) { // create a message to display in our view

    $scope.newPromocode = function(){


        $scope.onSubmit = function(){
            console.log($scope.form);
            // $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
            //$http.defaults.headers.post["Content-Type"] = "text/plain";
            var request = $http({
                method: "POST",
                url: "backend/statistics/promo",
                data: {
                    promocode : $scope.form.codetxt,
                    discount : $scope.form.discount,
                    minvalue : $scope.form.minvalue
                },
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            }).success(function (data) {
                alert(data);
            });
        }

    };

});

})(angular, angular.module('app'));`

route

Route::post('statistics/promo', ['uses' => 'Api\Backend\Statistics@promoCode']);


Answers

Answered by: Farrukh Subhani at 2017-07-11 07:54PM



Make sure url used by Angular and route definition for backend are same. It appears that url used in Angular is not defined as a proper route in laravel. /api/backend or /backend try to hit the angular url in browser and check what response you are getting.




Source

No comments:

Post a Comment

Adbox