Image Upload Ajax Jquery November 17, 2022 Post a Comment Im new to jQuery. I try to upload a jpg image file by using ajax method. But when I upload, it doesn't upload. Could anyone please help me to do this? HTML Solution 1: To upload file using ajax you must need to use FormData like below. $("form").on('submit', (function(e) { e.preventDefault; var formData = new FormData(this); $.ajax({ url : "upload.php", type : "POST", data : formData, cache : false, contentType : false, processType : false, success : function(data) { alert(data); } }); })); Copy And your PHP script should be like below. Baca JugaOffset When Drawing On CanvasHow To Update/change Html Content With Javascript And Prevent The Page From Refreshing?Is Valid Html5 Ok To Use Now? <?php $image=$_FILES['image']; $image_tmp =$_FILES['image']['tmp_name']; $imagename=date("d-m-Y")."-".time().".jpg"; $target_path = "uploads/".$imagename; if(move_uploaded_file($image_tmp, $target_path)) { echo 'moved'; } else { echo 'error'; } ?> Copy Share You may like these posts$_post Undefined Index Php ErrorGet Id Of Clicked Element Without Putting Any Js Code In The HtmlIncreasing The Size Of A Input Field In Html/css/jsAlign Decimal Data In Table Column By Decimal Point, Html5, Css3 Post a Comment for "Image Upload Ajax Jquery"
Post a Comment for "Image Upload Ajax Jquery"