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, "
");
                    alert("提交失败,错误原因:
" + 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中不能携带 ,在后台使用自定义的取代字符(我这里用的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("
", "enter");
                resultStr.Append("","error":"" + checkResult + ""}");

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

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



经验分享 程序员 微信小程序 职场和发展