1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > angularjs $http事务实现form表单序列化提交

angularjs $http事务实现form表单序列化提交

时间:2024-07-01 13:46:32

相关推荐

angularjs $http事务实现form表单序列化提交

在angularJs中前后端数据交互时 在添加时需要对form表单进行处理,并通过$http提交

需要注意 :

1. $http()参数列表为Json数组

2. 需要对form表单数据进行序列化处理

3. 配置请求头信息

添加 Demo,使用angularJs

Style.js文件

angular.module("myApp", []).controller("myController", function($scope, $http) {var HALF_URL = 'http://localhost/app/'; $scope.save = function() {$http({method: 'post',//请求方式url: HALF_URL + 'user/addUser',//请求路径data: $("#myForm").serialize(),//对form表单内容进行序列化headers: {'Content-Type': 'application/x-www-form-urlencoded'}//请求头信息}).then(function successCallback(response) {if(response.data.code == 200) {$scope.getUser();//成功刷新页面} else if(response.data.code == 400) {alert(response.data.msg);}}, function errorCallback() {alert("添加失败了哟!");});}});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。