jQuery / AngularJS - Upload file with AJAX -
somebody can answer please, once , all, if possible upload files using ajax?
i read few posts on web stating file upload using ajax impossible!
if possible, can please provide working piece of code of ajax request?
i tried 10 examples found on web , no 1 working.
please not refer me plugins. understand how works , implement myself.
thanks in advance!
try this,
html
<input id="pic "type="file" name="file" onchange="javascript:this.form.submit();">
js:
$("#pic").change(function() { var file_data = $('#pic').prop('files')[0]; var form_data = new formdata(); form_data.append('file', file_data) alert(form_data); $.ajax({ url: 'upload.php', datatype: 'text', cache: false, contenttype: false, processdata: false, data: form_data, type: 'post', success: function(dat){ alert('it works maybe'); } }); });
Comments
Post a Comment