显示上传进度

本节的任务是在上一节的基础上,加上上传进度显示:

实现起来非常简单:

1、在"d:\web"目录下,建立一个子目录lib,在这个目录建立一个文本文件,文件名为"ajaxform.js",文件内容为:

function submitWithProgress(){
    var result = submitAjaxForm('form1','afterSubmit',true,'tst1');
}


function afterSubmit(result){
    hide("tst1");
    if (result=='OK') {
        show("tst2");
        location="upload.htm";
    }
    else{
        show("tst3",2000);
    }
}

提示:

a、submitAjaxForm函数的第4个参数,用于指定一个Toast的ID,系统将通过这个Toast显示上传进度。
b、这里同样是采用异步上传,所以第三个参数要设置为true(不是True)。

2、HttpRequest事件代码则完全不变(注意JS函数名改了):

Select Case e.Path
    Case "upload.htm"
        Dim wb As New weui
        wb.AddForm("","form1","receive.htm")
        With wb.AddInputGroup("form1","ipg1",
"
文件上传")
            With .AddUploader("up128",
"
照片",True)
                .AllowDelete = True
'
允许删除
                .Incremental = True
'
允许重复选择文件或连续拍照
            End With
        End With
        With wb.AddButtonGroup("form1","btg1",True)
            .Add("btn1",
"
确定", "button").Attribute= "onclick='submitWithProgress()'" '调用js函数上传
        End With
        wb.AddToast("","tst1",
"
正在上传",1)
        wb.AddToast("","tst2",
"
上传成功",0)
        wb.AddToast("","tst3",
"
上传失败",0).Icon= "warn"
        wb.AppendHTML("<script src='./lib/ajaxform.js'></script>")
'
引入脚本文件
        e.WriteString(wb.Build)
'
生成网页
    Case "receive.htm"
        For Each key As String In e.Files.Keys
            For Each fln As String In e.Files(key)
               
e.SaveFile(key,fln,"d:\web\uploadfiles\" & fln) '保存接收到的文件
            Next
        Next
        e.WriteString("OK")

End
Select


本页地址:http://www.foxtable.com/mobilehelp/topics/0139.htm