The Ajax submit form allows you to serialize the form form and then submit the data to the background, such as:
$.ajax ({url: "http://localhost:8080/", type: "POST", Data: $ (' #postForm '). Serialize (), Su Ccess:function (data) {}, Error:function (data) {}}); But this way if you have a file type that you want to submit in your form, then you can't get the data back in the background.
Solution: Use FormData. It is best to use jquery here after the 2.0 version should not be supported. For example:
<form id= "Form" >
<p class= "P5" ><span><i>*</i> Merchant certificate:</span>
Type= ' text ' name= ' apiclienttype ' id= ' TextField ' class= ' w_txt ' > <input type= ' button ' class= ' w_btn ' value= '
Upload certificate '/>
<input type= "file" Name= "Filefield" class= "W_file" id= "" Filefield "" size= " document.getElementById (' TextField '). value=this. Value "/>
</P>
</form>
FormData (document.getElementById ("form"))//form ID
$.ajax ({
URL: '${ctx}/wmmanage/ Saveweixinconfig.do ',
type: ' POST ',
data:formdata,
false,
false,
False,
false,
(Result) {
}
});
Enclosed background data receive:
@RequestMapping ("/saveweixinconfig")
@ResponseBody public
resultmsg saveweixinconfig (@RequestParam ( Value = "Filefield", required = False) Multipartfile Filefield) throws IOException {return
"";
}