angularjs post 後臺 取不到值,修改contentTye 可以解決

java_陳序猿發表於2017-07-07
var app = angular.module('maplePointApp', []);
app.config(["$httpProvider", function ($httpProvider) {
    //更改 Content-Type
    $httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8";
    $httpProvider.defaults.headers.post["Accept"] = "*/*";
    $httpProvider.defaults.transformRequest = function (data) {
        //JSON資料轉換成字串形式
        if (data !== undefined) {
            return $.param(data);
        }
        return data;
    };
}])
app.controller('myCtr', function($scope,$http) {
    $scope.initIndex = function () {
        $http({

            method : "post",
            url : "${REQ}/maple/point",
            data : {
                "id" : 123
            }
        }).success(function(rs) {
            console.log(rs)
            $scope.dataList=rs;

        }).error(function(rs) {
        });
    }
});

相關文章