目前,我的表单元素如下所示:
<form enctype="multipart/form-data" name="copyReplaceForm" method="POST" action="/app/applications/copyreplace/postCsv">
但不要给出 action
, enctype
和method
关于<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;
}
});
}
最佳答案
xhrPost中的url和@Path注解中指定的路径不相同。
您应该向 xhrPost 添加一个 form
属性。
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;
}
});
}
关于javascript - 如何通过xhrPost()发送csv文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41928694/