post data - ngResource AngularJS

后端 未结 4 844
你的背包
你的背包 2021-01-24 14:38


Hello !
I develop a RESTful webapp with AngularJS, I use the ngResource module to send http requests. The webservice is developped with FuelPHP.

I\

4条回答
  •  孤独总比滥情好
    2021-01-24 15:14

    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);  
        }  
    });
    

提交回复
热议问题