jquery - It is possible send other data together with files in ajax? -
i'm uploading files through ajax interaction. i'd send, together, information in order build path in server side. don't know if possible , how it.
function uploadfd(){ var omyform = new formdata(); jquery.each(jquery('#file')[0].files, function(i, file) { omyform.append('file-'+i, file); }); $.ajax({ url: 'filecontroller', data: omyform, processdata: false, contenttype: false, type: 'post', success: function(data){ $('#result').html(data.msg); $.messager.show({ title : 'success', msg : data.msg, showtype : 'show' }); } }); }
controller:
@requestmapping(method = requestmethod.post, headers = "content-type=multipart/*") public void upload(multiparthttpservletrequest request, httpservletresponse response) { response.setcharacterencoding("utf-8"); iterator<string> itr = request.getfilenames(); multipartfile mpf = request.getfile(itr.next()); system.out.println(mpf.getoriginalfilename() +" uploaded!"); //... other stuff }
how it? thanks!
yes possible. second parameter formdata.append
can simple string:
omyform.append('param', 'value');
and can access parameter value on server via request.getparameter()
:
string v = request.getparameter("param");
Comments
Post a Comment