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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM