zoukankan      html  css  js  c++  java
  • Jquery ajax上传文件到服务器

    添加引用

    <script src="/js/ajaxfileupload.js"></script>

     js文件 https://files.cnblogs.com/files/tengfei8/ajaxfileupload.js

    上传附件代码:

     1 //文件上传
     2 function ajaxFileUpload() {
     3     $.ajaxFileUpload
     4     ({
     5         url: '/ApproveListHandler.aspx?Type=UpLoadAttachment', //用于文件上传的服务器端请求地址
     6         secureuri: false, //是否需要安全协议,一般设置为false
     7         fileElementId: 'txtAttachment', //文件上传域的ID
     8         dataType: 'json', //返回值类型 一般设置为json
     9         success: function (data, status)  //服务器成功响应处理函数
    10         {
    11             if (typeof (data.error) != 'undefined') {
    12                 if (data.error != '') {
    13                     $("#attTable").append("<tr class='attContent'><td class='att_title' colspan='2' >" + "附件添加失败" + "</td></tr>");
    14                 } else { 
    15                     var displayName = data.oldFileName;
    16                     var fullname = data.fileName;
    17                     allAttFullPath = allAttFullPath + fullname + "*";
    18                     $("#hdAttContent").val(allAttFullPath);
    19                     $("#attTable").append("<tr class='attContent'><td class='att_title'>" + displayName + "</td><td onclick='delTr(this);' class='delTd'><input type='hidden' value='" + fullname + "' /><img src='/images/selected/list_delete.png'></td></tr>");
    20                       }
    21             }
    22         },
    23         error: function (data, status, e)//服务器响应失败处理函数
    24         {
    25             $("#attTable").append("<tr class='attContent'><td class='att_title' colspan='2' >" + "附件添加失败,服务器响应失败,请联系管理员" + "</td></tr>");
    26         }
    27     });
    28     return false;
    29 }
    View Code
  • 相关阅读:
    线性代数学习笔记(代数版)
    洛谷P2765 魔术球问题(贪心 最大流)
    洛谷P2770 航空路线问题(费用流)
    洛谷P4013 数字梯形问题(费用流)
    洛谷P2774 方格取数问题(最小割)
    洛谷P2761 软件补丁问题(状压DP,SPFA)
    项目mysql数据导入数据的Java程序
    axd与ashx区别
    LD1-K(求差值最小的生成树)
    rabbitMQ入门
  • 原文地址:https://www.cnblogs.com/tengfei8/p/7110599.html
Copyright © 2011-2022 走看看