1

我的应用程序需要上传文件。为此,我有一个带有上传器和按钮的表单。该按钮应该触发一个休息方法。rest 方法需要一些参数 + 上传器有效负载。如何为此获取上传器有效负载?

var up = new Uploader({ 
    name: "File",
    label: "Select file",
    id: "uploader",
    multiple: false,
    uploadOnSelect: false,
    url: "to/the/ethreal" //This should be defined in the submit action of the button.
}).placeAt(div);

new Button({
    label: "OK",
    onClick: function () {

        // Get payload. Something like up.getPayloadStream();

        // TODO: REST Function.
        $.ajax({
            async: true,
            url: 'my/rest/resource',
            type: 'POST',
            contentType: 'text/json',
            data: payload,

            ...
        });
    }
}).placeAt(actionBar);

编辑:

现在我的方法是这样的,但它仍然行不通:

var form = new Form({
    id: 'addForm',
    method: 'POST',
    action: 'my/proxy.aspx',
    encType: 'multipart/form-data'
});

var p = dojo.create("div", {}, form.domNode);
var up = new Uploader({ 
    name: "File",
    label: "Select file",
    id: "addDia",
    multiple: false,
    uploadOnSelect: false//,
    //url: "to/the/ethreal"
}).placeAt(p);


new Button({
    label: "OK",
    onClick: function () {

    // TODO: REST Function.
    ioIframe.send(form.action, {
        form: dojo.byId('addForm'),
            handleAs: "html"
        }).then(function (data) {
            //Worked
            console.log("success");
        }, function (error) {
            //Didnt
            console.log("error");
        });
     }
 }).placeAt(actionBar);
4

0 回答 0