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

  • 相关阅读:
    Codeforces Round #297 (Div. 2) 525C Ilya and Sticks(脑洞)
    全栈必备 JavaScript基础
    2014-04-19编程之美初赛题目及答案解析
    doT js模板入门 2
    一篇关于arc下内存管理的老文章,包含各种冷门修饰符(关于内存),写的较好,mark
    MyBatis官方教程及源代码解析——mapper映射文件
    Android中图片的三级缓存策略
    python字符串/元组/列表/字典互转
    关于字节对齐的理解
    阿里云服务器ecs配置之安装redis服务
  • 原文地址:https://www.cnblogs.com/suizhikuo/p/9192159.html
Copyright © 2011-2022 走看看