廢話不多說了,直接給大家貼代碼了。
$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表單提交的實現代碼,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對雲棲社區網站的支援!