Wednesday, 15 May 2013

php - Simple jQuery AJAX file upload -



php - Simple jQuery AJAX file upload -

i'm totally noob in jquery , become desperate work.

this html:

<form method="post" enctype="multipart/form-data"> <input id="pic "type="file" name="file" onchange="javascript:this.form.submit();"> </form>

jquery:

$("#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: 'doupload.php', datatype: 'text', cache: false, contenttype: false, processdata: false, data: form_data, type: 'post', success: function(dat){ alert('it works maybe'); } }); });

so want send file doupload.php , grab there ($_files['file']['tmp_name'])

but it's not working (ofc) , don't find working either google nor stack...

i utilize lilbary: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>

<input id="pic "type="file" name="file" onchange="javascript:this.form.submit();">

you have "type="file"

change type="file"

also, if have ajax sending on alter via "$("#pic").change(function() { should not have onchange="javascript:this.form.submit();" well, submit form while ajax still sending, causing possible timing issues (such ajax phone call not completing)

as far can tell, should not have submit event @ all, info submitted via ajax call.

php jquery file-upload

No comments:

Post a Comment