Saturday, March 18, 2017

Angular $http sends get instead of post

$http.post(main+'/api/getcard/', $.param({number: $scope.searchcard}), {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} })
        .then(function (response) {
            if(response.data != 0)
            {
                $location.path('/redeem/'+response.data.id);
                console.log(response.data);
            }
        });

When i use this code my chrome sends:

Request URL:http://cards.mporeda.pl/branch/api/getcard
Request Method:GET
Status Code:405 Method Not Allowed

But when i use the same code on laravel serve localhost:8000 i get:

Request URL:http://localhost:8000/branch/api/getcard/
Request Method:POST
Status Code:200 OK

I don't have any more $http configurations only this header option in request. I have no errors on console before this request, so i quess my code is ok. Is there any problem with my server or something?



via MichaƂ Poreda

Advertisement