Saturday 15 March 2014

php - Ajax Upload image -



php - Ajax Upload image -

q.1 convert form ajax seems ajax code lacks something. on submit doesn't @ all.

q2. want function fire on alter when file has been selected not wait submit.

here js.

$('#imageuploadform').on('submit',(function(e) { e.preventdefault() $.ajax({ type:'post', url: $(this).attr('action'), data:$(this).serialize(), cache:false }); }));

and html php.

<form name="photo" id="imageuploadform" enctype="multipart/form-data" action="<?php echo $_server["php_self"];?>" method="post"> <input type="file" style="widows:0; height:0" id="imagebrowse" hidden="hidden" name="image" size="30"/> <input type="submit" name="upload" value="upload" /> <img width="100" style="border:#000; z-index:1;position: relative; border-width:2px; float:left" height="100px" src="<?php echo $upload_path.$large_image_name.$_session['user_file_ext'];?>" id="thumbnail"/> </form>

first in ajax phone call include success & error function , check if gives error or what?

your code should

$(document).ready(function (e) { $('#imageuploadform').on('submit',(function(e) { e.preventdefault(); var formdata = new formdata(this); $.ajax({ type:'post', url: $(this).attr('action'), data:formdata, cache:false, contenttype: false, processdata: false, success:function(data){ console.log("success"); console.log(data); }, error: function(data){ console.log("error"); console.log(data); } }); })); $("#imagebrowse").on("change", function() { $("#imageuploadform").submit(); }); });

php jquery html ajax

No comments:

Post a Comment