post data - ngResource AngularJS

痴心易碎 提交于 2019-12-02 04:39:06

I believe this is an issue with how PHP is handling the POST. When using AngularJS $resource it will POST the object with JSON as the post's BODY. PHP does not see this as a regular parameter. I've had to do this in other PHP (never used Fuel)

$requestBody = file_get_contents('php://input');
$requestBody = json_decode($requestBody, true);

Then you should be able to inspect $requestBody as a normal json object.

You need to config the $save method with a request method of 'POST'

you can set the default option 'transformRequest' of $http to change the transfer formation of the post data.

var myApp = angular.module('myApp');  

myApp.config(function ($httpProvider) {  
    $httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    $httpProvider.defaults.transformRequest = function(data){  
        if (data === undefined) {  
            return data;  
        }  
        return $.param(data);  
    }  
});

Thanks for your answers.
Indeed, data is post in the request's body.
With FuelPHP, I used Input::json('key') to get the values (and not Input:post('key'))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!