1

目前,我的表单元素如下所示:

<form enctype="multipart/form-data" name="copyReplaceForm" method="POST" action="/app/applications/copyreplace/postCsv">

但我不想给action,enctypemethod,<form>我想用dojo.xhrPost().

有人可以告诉我如何发送使用xhrPost吗?

此外,我的 REST 代码如下所示:

@POST
@Path("/bulkCopyReplaceFirst")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.MULTIPART_FORM_DATA)

我的 xhrPost 如下所示

var result;
dojo.xhrPost({
        url :"/CopyReplace/bulkCopyR",
        preventCache: true,
        contentType : "multipart/form-data",
        load: function(response) {
                txtResponse = response;
                console.log("response is : txtResponse"+txtResponse)
        },
        error: function(error, ioArgs) {
                console.log("postImageOptions() ERROR :: " + error);
                console.log("postImageOptions() ioArgs :: " + ioArgs);
                return error;
        }


    });
}
4

2 回答 2

0

您可以直接使用 Dojo Uploader。

var up = new Uploader({
            label: "Upload csv",
            multiple: false,       // true if you can upload more files
            uploadOnSelect: false,   // true if you want to upload without clicking on the submit of the from
            url: "/path/name.csv",   // the route path to the backend (xhr url)
            style: "",
            onBegin: function() {
               // start of upload
            },
            onProgress: function(rev) {
               // uploading...
            },
            onChange: function() {
               // on file change
               var file = up.getFileList();
             }
         }, this.domNode);
于 2017-04-11T14:10:17.173 回答
0

xhrPost 中的 url 和 @Path 注解中指定的路径不一样。

您应该form向 xhrPost 添加一个属性。

var result;
dojo.xhrPost({
        url :"/bulkCopyReplaceFirst",
        form: document.forms["copyReplaceForm"],
        load: function(response) {
                txtResponse = response;
                console.log("response is : txtResponse"+txtResponse)
        },
        error: function(error, ioArgs) {
                console.log("postImageOptions() ERROR :: " + error);
                console.log("postImageOptions() ioArgs :: " + ioArgs);
                return error;
        }


    });
}
于 2017-02-01T19:22:29.730 回答