首页 > 技术文章 > angularJS请求参数 ajax

zhuxiang1633 2018-12-03 18:41 原文

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

推荐阅读