AngularJS $http配置为form data 提交

AngularJS $http配置为form data 提交

$scope.formData = {};
$http({
        method: 'POST',
        url: '/user/',
        // pass in data as strings
        data: $.param($scope.formData), 
        // set the headers so angular passing info as form data (not request payload)
        headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' } 
    })
    .success(function(data) {
        console.log(data);

        if (!data.success) {
            // if not successful, bind errors to error variables
            $scope.errorName = data.errors.name;
            $scope.errorSuperhero = data.errors.superheroAlias;
        } else {
            // if successful, bind success message to message
            $scope.message = data.message;
        }
    });
posted @ 2016-09-09 21:19  CooMark  阅读(6006)  评论(0编辑  收藏  举报