• 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”});
            }

  • 相关阅读:
    类型转换
    希尔排序
    冒泡排序
    More Effective C++ (静态绑定与动态类型)
    More Effective C++ (限制类的对象数量)
    算法复杂度
    交换两个数的方法
    QString类(常用函数)
    面向过程与面向对象
    QTableWidget控件总结
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/9192159.html
Copyright © 2020-2023  润新知