jQuery ajax, send form with input type file and Json -
i have form several inputs , other field.
i have save button, , when click, send form ajax jquery :
$.ajax({ type: "post", datatype: "json", url: $('#ajaxurl').val(), data: "action=save&" + form.serialize() });
so, when have simple input text, select etc.. it's ok. if have input type file, can't retrieve file. $_files empty.
how can possible ?
edit : don't want use plugin :)
implementation asp.net mvc:
to start making form-wrapper :
<form id="inputform"> <input class="hide" type="file" name="file" id="file" /> </form>
Сreate client-handler send:
$("#yourbutton").bind('click', function () { var data = new window.formdata($('#inputform')[0]); $.ajax({ xhr: function () { return $.ajaxsettings.xhr(); }, type: "post", data: data, cache: false, contenttype: false, processdata: false, url: "@url.action("methodname", "controllername")", success: function () { }, error: function () { }, }); });
do handler on server side (controller):
public actionresult methodname(httppostedfilewrapper file) { var img = image.fromstream(file.inputstream); .... return ..; }
i hope save time ;)
Comments
Post a Comment