This article gives you a detailed analysis of the $http asynchronous uploading method of Excel files in angularjs. Readers in need can learn about it.
1. The html code of the file upload box is as follows
*Note: Set the enctype attribute value of the form to: multipart/form-data
2: The js code is as follows:
$scope.import_asset = function () { $("#file_asset").click(); }; $("#file_asset").on("change", function(){ var formData = new FormData(); var file = document.getElementById("file_asset").files[0]; if(file.name){ var fileName = file.name.substring(file.name.lastIndexOf(".") + 1); if(fileName =="xlsx" || fileName =="xls"){ formData.append('file', file); $http({ method:"post", url:commonService.projectName + "/so/assetmanage/upload", data:formData, headers : { 'Content-Type' : undefined }, transformRequest : angular.identity }).then(function (response) { if(response.status == 200){ alert("文件上传成功!!!"); }else{ alert("文件上传失败!!!"); } }); }else{ alert("文件格式不正确,请上传以.xlsx,.xls 为后缀名的文件。"); $("#file_asset").val(""); } } });
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
How to create an instruction to upload photos in AngularJS (detailed tutorial)
How to dynamically add Li in javaScript Instance of element
The above is the detailed content of Use $http to implement asynchronous uploading of Excel files in angularjs. For more information, please follow other related articles on the PHP Chinese website!
Compare the similarities and differences between two columns of data in excel
excel duplicate item filter color
How to copy an Excel table to make it the same size as the original
Excel table slash divided into two
Excel diagonal header is divided into two
Absolute reference input method
java export excel
Excel input value is illegal