<input type= "File" Name= "File1" id= "File1" onchange= "uploadimg (' file1 ', ' Hidden1 ')" >
<input type= "hidden" id= "Hidden1"/>
Asynchronous upload File Method
function Uploadimg (Fileid,hiddenid) {
$.ajaxfileupload
(
{
URL: '/xxx/xxx ',
Secureuri:false,
Fileelementid:fileid,
DataType: ' JSON ',
Success:function (data, status)
{//data's content is customized in the background PHP code, and the JSON format is returned here as an object-based access
if (typeof (data.errmsg)! = ' undefined ') {//Upload file Error
alert (data.errmsg);
}else{
Alert (' OK ');
$ ("#" +imgid). attr ("src", Data.path). addclass ("Load1");//load the returned picture path with a style
$ ("#" +hiddenid). Val (Data.path); Assigns a value to the corresponding hidden field so that it is submitted to the background
}
},
Error:function (data, status, E)
{
Console.log (data);
}
}
)
}
@RequestMapping (/XXX/XXX)
@ResponseBody
Public map<string, object> UploadFile (Multiparthttpservletrequest request) {
map<string, object> map = new hashmap<string, object> ();
iterator<string> names = Request.getfilenames ();
Multipartfile file = Request.getfile (Names.next ());
....
Save File
}
}
$.ajaxfileupload must return the Map object, return the string type to receive an error, error error:syntax error, unrecognized expression: {...}