zoukankan      html  css  js  c++  java
  • fromdata上传文件,ajax上传文件, 纯js上传文件,html5文件异步上传

    前端代码:

    上传附件(如支付凭证等)
    <input type="file" name="fileUpload" id="fileUpload" />
    <ul id="imgPanle" style=" 300px"></ul>

    <script type="text/javascript">
         $(document).ready(function() {
             $("#fileUpload").change(function() {
             
                 var formData = new FormData(); // FormData 对象
                 formData.append("fileUpload", document.getElementById("fileUpload").files[0]); // 文件对象

                $.ajax({
                     type: 'post',
                     url:  “/Attachment” //后台方法的路径
                     data: formData,
                     cache: false,
                     processData: false,
                     contentType: false
                 }).success(function (tempdata) {
                     alert(data);
                    
                 }).error(function () {
                     alert("上传失败");
                 });
             });
         });

       
    </script>

    asp.net

    后端代码

    /// <summary>
            /// 上传附件
            /// </summary>
            /// <param Name="file"></param>
            /// <param Name="OrderID"></param>
            /// <returns></returns>
            public ActionResult  Attachment(HttpPostedFileBase fileUpload, string OrderID)
            {
                //文件名
                var Name = System.IO.Path.GetFileName(fileUpload.FileName);
                System.IO.Stream str;
                int strLen;
                str = fileUpload.InputStream;
                strLen = Convert.ToInt32(str.Length);
                byte[] strArr = new byte[strLen];
                str.Read(strArr, 0, strLen);
                str.Close();

                           return Json(new{result=”OK”});
            }

  • 相关阅读:
    poj 2406 Power Strings【最小循环节】
    hdoj 2087 剪花布条
    hdoj 1054 Strategic Game【匈牙利算法+最小顶点覆盖】
    hdoj 1151 Air Raid
    hdoj 2502 月之数
    hdoj 1862 EXCEL排序
    hdoj 1200 To and Fro
    hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
    hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
    uva1563
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/9192159.html
Copyright © 2011-2022 走看看