AngularJS模仿Form表单提交的实现代码
程序员文章站
2023-11-11 22:41:28
废话不多说了,直接给大家贴代码了。
$http({
url: "http://localhost:10086/yuanxin/conference/import...
废话不多说了,直接给大家贴代码了。
$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表单提交的实现代码,希望对大家有所帮助