zoukankan      html  css  js  c++  java
  • jquery ajax 上传文件

    html
                //获取客户端上传的文件集合
                HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
                //相对路径
                string path = "";
                //判断文件是否存在
                if (files.Count > 0) {
                    //获取扩展名
                    string extension = Path.GetExtension(files[0].FileName);
                    if (!string.IsNullOrEmpty(extension))
                    {
                        path = "/Content/images/" + Guid.NewGuid() + extension;
                        //获取文件集合中的第一个文件(每次只上传一个文件)
                        HttpPostedFile file = files[0];
                        string fullpath = System.Web.HttpContext.Current.Server.MapPath(path);
                        file.SaveAs(fullpath);
                    }
                }
    后台代码
         $.ajaxFileUpload({
                url: '/MarketingStrategyModule/MarketingStrategy/SaveMarketingBookForm?keyValue=' + keyValue,
                data: {
                    name: entity.name, rule_rights: entity.rule_rights,
                    state: entity.state, is_member: entity.is_member, start_date: entity.start_date,
                    end_date: entity.end_date, dsc: entity.dsc, terminal: entity.terminal, members: entity.members,
                    products: entity.products.replace(new RegExp('"', "gm"), "'")  //entity.products是一个数组,需要先转成JSON后,再进行正则替换,否则后台接受到的是“【{”
                },
                type: "POST",
                fileElementId: 'uploadFile',
                dataType: 'json',
                success: function (data) {
                    bpm.loading(false);
                    if (data.code == 200) {
                        //保存成功后才回调
                        if (!!callBack) {
                            callBack();
                        }
                        bpm.alert.success('保存成功');
                        bpm.layerClose(window.name);
                    } else {
                        bpm.alert.warning(data.info);
                    }
                }
            });
    View Code
  • 相关阅读:
    IE8中li添加float属性,中英数字混合BUG
    jQuery ajax get与post后台交互中的奥秘
    BZOJ 4816 数字表格
    BZOJ 1598 牛跑步
    BZOJ 4077 Messenger
    相关分析 BZOJ 4821
    Crash的数字表格 BZOJ 2154 / jzptab BZOJ 2693
    回文串 BZOJ 3676
    古代猪文 BZOJ 1951
    树上的路径 BZOJ 3784
  • 原文地址:https://www.cnblogs.com/xielideboke/p/11136641.html
Copyright © 2011-2022 走看看