$.ajaxfileupload must return the Map object, return the string type to receive an error, error error:syntax error, unrecognized expression: {...}

Source: Internet
Author: User
Tags save file

<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: {...}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.