javascriptangularjslaravellaravel-5angular-file-upload

AngularJS $http POST turn into GET


I have a route

Route::post('/updateLogo', 'CaptivePortalController@updateLogo');

Then I make a POST here

$http({
    method: 'POST', <----- I did a POST 
    url: '/updateLogo',
    headers: { 'Content-Type': undefined },
    transformRequest: function (data) {
        console.log("data coming into the transform is ", data);
        var formData = new FormData();
        formData.append("company_logo_path", data.files);
        console.log($scope.files.company_logo_path);
        return formData;
    },
    data: { files: $scope.files.company_logo_path }
})

.then(function successCallback(response) {
    console.log("success");
    console.log(response);
    $('.save-fade').delay(500).fadeOut(1000);
}, function errorCallback(response) {
    console.log("fail");
    console.log(response);
});

When I browse the file, and submit the form, I kept getting

405 in my Network tab on Chrome Dev Tool.


Then, I click on it, I see

MethodNotAllowedHttpException in RouteCollection.php line 218:

enter image description here

I know that I'm NOT suppose to make a GET to a POST route, but Why does it make a GET request instead of a POST?

Request URL:http://l.ssc.com:8888/en/updateLogo
Request Method:GET <------ 
Status Code:405 Method Not Allowed
Remote Address:127.0.0.1:8888
Referrer Policy:no-referrer-when-downgrade

What did do wrong here ?

Any hints ?


Solution

  • This looks like a re-direction taking place. refer : $http.post() method is actally sending a GET

    Please check your route configuration at the server, make sure it is exactly the same as you're requesting.

    If you're requesting a '/myroute' but you've defined the route as '/myroute/' then your server could be redirecting to '/myroute'.

    All re-directions are done using a GET. And since the route doesn't allow GET request, it's returning a 405.