jquery - Javascript: TypeError: Value does not implement interface FormData -
i'm trying use formdata send data via ajax php script. there doesn't seem problem input type text values when try append files error typeerror: value not implement interface formdata.
i new formdata, searched on web , couldn't find doc on error.
here's form :
<form id="item_form" class="item_form" enctype="multipart/form-data"> <div class=""> <label for="emp_photos">photos</label> <input id="emp_photos" class="inputtext" type="file" value="" name="emp_photos"> </div> </form>
here's javascript :
var formdata = new formdata(); formdata.append('photos', $('#emp_photos').files[0]);
here's error in firebug :
typeerror: value not implement interface formdata. ...igger("ajaxcomplete",[n,p]),--b.active||b.event.trigger("ajaxstop")))}return n},... jquery....min.js (line 5)
what doing wrong here ?
edit: ajax part
$.ajax({ type: 'post', url: '"; echo $_session["url_base"]; echo "operations/add_employes', data: formdata, xhr: function() { // custom xhr myxhr = $.ajaxsettings.xhr(); if(myxhr.upload) { // check if upload property exists myxhr.upload.addeventlistener('progress',progresshandlingfunction, false); // handling progress of upload } return myxhr; }, success: function(msg) {/*...*/} });
var inputs = $("input[type=file]"), files = []; // jquery or javascript have different notation // it's either accessing functions () or arrays [] depending on object you're holding @ moment (var = 0; < inputs.length; i++){ files.push(inputs.eq(i).prop("files")[0]); //files.push(inputs[i].files[0]); //filename = inputs[i].files[0].name; //filesize = inputs[i].files[0].size; } if (formdata) { // can use array notation of input's `name` attribute here formdata.append("emp_photos[]", files); }
Comments
Post a Comment