ajaxfileupload上传文件成功,但是无法获取到值

<script src="~/Scripts/jquery-1.7.1.js"></script>
    <script src="~/Scripts/json2.js"></script>
    <script src="~/Scripts/ajaxfileupload.js"></script>

<script>


<div style="padding-left: 80px;">
    <input id="fileUpload1" name="fileUpload1" type="file" />
    <br />
    <br />

name值必须有的!
    <br />
    <br />


    <input type="button" id="btnReader" name="btnReader" value="确定" style="width: 80px; height: 35px" οnclick="reader()" />


</div>


function reader()

    $.ajaxFileUpload({
        url: '../TxtReader/Reader', 
      //  cache: false,
       // async: false,
        fileElementId: 'fileUpload1',
        dataType: 'json',
        success: function (data, status) {
             
            alert("Success");
        } ,
        error: function (data, status, e) {
            alert(e);
        }


    });
}


</script>



/// <summary>
        /// 读取文件
        /// </summary>
        /// <returns></returns>
        public string Reader()
        {
             HttpFileCollectionBase files = Request.Files;
             HttpPostedFileBase file = files["fileUpload1"];
            string filepath;
            string filename;
            if (file == null || file.ContentLength <= 0)
            {
                return "0"; //没有选择需要的上传文件
            }
            try
            {
                filepath = GetMapPath("../ExcelFolder/");
                filename = Guid.NewGuid().ToString() + file.FileName.Substring(file.FileName.IndexOf('.'));
                file.SaveAs(Path.Combine(filepath + filename));
            }
            catch (Exception err)
            {
               
            }


            return "0";
        }


        /// <summary>
        /// 获得当前绝对路径
        /// </summary>
        /// <param name="strPath">指定的路径</param>
        /// <returns>绝对路径</returns>
        public string GetMapPath(string strPath)
        {
            if (HttpContext.CurrentHandler != null)
            {
                return HttpContext.Server.MapPath(strPath);
            }
            else //非web程序引用
            {
                strPath = strPath.Replace("/", "\\");
                if (strPath.StartsWith("~"))
                {
                    strPath = strPath.TrimStart('~');
                }
                if (strPath.StartsWith("\\"))
                {
                    strPath = strPath.TrimStart('\\');
                }
                if (strPath.Substring(0, 4) == "bin\\")
                {
                    strPath = strPath.Substring(4);
                }


                return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
            }
        }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值