摘要:本文通过一段实例代码给大家简单介绍了angularjs模仿form表单提交的方法。$http({ url: "http://localhost:10086/yuanxin/Conference/ImportExcelDataForBusRoute", method: 'Post', headers: { 'Content-T
本文通过一段实例代码给大家简单介绍了angularjs模仿form表单提交的方法。
$http({ url: "http://localhost:10086/yuanxin/Conference/ImportExcelDataForBusRoute", method: 'Post', headers: { 'Content-Type': 'multipart/form-data' }, data: { BusRoute: file, ConferenceID: "1" }, transformRequest: function (data, headersGetter) {//进行格式转换,非常关键 var formData = new FormData();//将model转为表单格式 angular.forEach(data, function (value, key) { formData.append(key, value); }); var headers = headersGetter(); DELETE headers['Content-Type']; return formData; } }).success(function (data) { $scope.isSubming = false; $scope.BusRouteColl = data.dataList; $scope.pageIndex = 1; $scope.pageCount = data.pageCount; //alert(data.property.mp); }).error(function (ex, state) { alert(ex); console.log(state + ":" + ex.exceptionMessage); console.log(ex.stackTrace); $scope.isSubming = false; });
更多关于AngularJS模仿Form表单提交的实现代码请关注PHP中文网(m.sbmmt.com)其它文章!