how to upload file using dojo

别说谁变了你拦得住时间么 提交于 2019-12-09 13:56:17

问题


How do I browse to upload a file using Dojo? See the code below:

 dojox.io.xhrMultiPart({
              url: "http://localhost:8080/myWebService",
              handleAs: "xml",
              form: dojo.byId("myForm"), 
              load: function(data){ processRequest(data);},
              error: function(error){ processError(error); },
              backButton: function() { 
              },
              mimetype: "text/xml"         
        });

Now which code do I have to append to the above code to upload a file?


回答1:


I use dojox.form.Uploader , which will enable you the "Browse" functionality.

<input name="file" multiple="false" type="file" dojoType="dojox.form.Uploader" label="Select Class File" id="uploadedfile" />

I use dojo.io.iframe.send to upload file. Then on the submit button of the form, I use following function to post,

function addSwitchType(){
    var td = dojo.io.iframe.send({
        url: switchType_Add_URL,
        form: formName,
        method: "post",
        preventCache: true, 
        handleAs: "json",
        load: function(response, ioArgs){

            },
        error: function(response, ioArgs){

            }
    });
}



回答2:


You can use dojox.form.Uploader along with dojox.form.uploader.FileList. Just declare these 2 as follows.

up = new dojox.form.Uploader({
    label: "Select files",
    multiple: true,
    class: "browseButton",
    url: "UploadFile.php"
}).placeAt(form);

list = new dojox.form.uploader.FileList({
    uploader: up
}).placeAt(form);

btn = new Button({
    label: "upload",
    onClick: function() {
        up.upload();
    }
}).placeAt(form);

btn.startup();
up.startup();
list.startup();


来源:https://stackoverflow.com/questions/11219973/how-to-upload-file-using-dojo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!