dojo uploader使用,ps.返回值

"dojox/form/Uploader",


//上传文件的处理路径
            var url = this.projectName + "/widgets/handler/FruitSubmit.ashx?methodName=FileUpload";
            this.fileupload  = new Uploader({
                label:"选择文件",
                url: url,
                multiple: false,
                uploadOnSelect: false
            }, this.fileUpLoaderNode);
            dojo.connect(this.fileupload, "onComplete", function (e) {
                if (e.error == "" || e.error == undefined || e.error == null) {
                    alert("提交成功!");
                }
                else {
                    var errorMsg = e.error.replace(/enter/g, "\n");
                    alert("提交失败,错误原因:\n" + errorMsg);
                }
            });
参数在url中携带,中文乱码问题使用encodeURI编码,后台使用System.Web.HttpUtility.UrlDecode(context.Request.Params["cityName"], Encoding.UTF8);解码

this.fileupload.url = this.projectName + "/widgets/handler/FruitSubmit.ashx?methodName=FileUpload&year=" +
                        this.sltYear.value + "&city=" + this.sltCity.value + "&cityName=" + encodeURI(this.sltCity.focusNode.textContent);;
                    this.fileupload.upload();
后台返回值为json形式,{"file":"web/a.zip","name":"a.zip","type":"zip"}。另:JSON中不能携带\r\n,在后台使用自定义的取代字符(我这里用的enter),到前台后在进行转换
<span style="white-space:pre">		</span>resultStr.Append("{\"file\":\"");
                resultStr.Append(context.Request.ApplicationPath);
                resultStr.Append("/" + postedFile.FileName);
                resultStr.Append("\",\"name\":\"" + postedFile.FileName);
                resultStr.Append("\",\"type\":\"" + postedFile.FileName.Split('.')[1]);

                checkResult = checkResult.Replace("\r\n", "enter");
                resultStr.Append("\",\"error\":\"" + checkResult + "\"}");

                //string str = "{\"file\":\"upload/file.zip\",\"name\":\"file.zip\",\"type\":\"zip\",\"error\":\""+checkResult+"\"}";
                //str = str.Replace("\r\n","enter");

                context.Response.Write(resultStr.ToString());



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值