[英]is this ajax call for below rest Service is correct or not?
樣本休息服務如下:
@RequestMapping(value = "/image/upload", method = RequestMethod.POST)
public void uploadImage(@RequestParam("image") MultipartFile fileObj)
throws Exception
{
System.out.print("File Name:"+fileObj.getOriginalFileName());
}
而且我寫了這樣的ajax代碼:當我調用此代碼時,我的接受應用程序格式為Json,我得到400錯誤
$('#user_click').click(function(){
var data = {
image:$("#file_1").val
};
$.ajax({
url : "http://localhost:8080/MyProject/image/upload",
type : "POST",
contentType : false,
crossDomain : true,
data : JSON.stringify(data),
dataType : 'json',
async : true,
success : function(result) {
alert('The Selected Items uploaded');
},
error: function(message){
alert("Error:"+JSON.stringify(message));
}
});
這個ajax代碼正確嗎?
不可以,因為ajax請求將不會傳輸文件數據,所以它將不起作用。
解決方案是
例如:
$('#myForm').ajaxSubmit({
url : 'http://localhost:8080/MyProject/image/upload',
type : "POST",
dataType : "json",
success : function(response) {
},
error : function(response) {
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.