angularJS请求参数 ajax

1. 使用angular服务请求

app.controller('main', function($scope, $http) {
    $scope.fun1 = function () {
        $http({
            method:'POST',
            url:'/user/addUser',
            {#params:{name:'admin',age:21},#}
            data:{name:'admin',age:22},
            dataType:'json',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
        }).then(function (response) {
             console.log(response.data)
        }, function (response) {
            // 请求失败执行代码
        });

    }
});

 

 

 

 

end

posted @ 2018-12-03 18:41  fight139  阅读(309)  评论(0编辑  收藏  举报