I am trying to upload image using PHP and AJAX.
Without AJAX, my image/file gets uploaded perfectly but when I try to using the AJAX so the page doesn't refresh, I get no image/file uploaded!
Here is my code:
My PHP code, as I stated above, this works fine without AJAX:
if (isset($_POST['u_id_im'])) {
if ($_FILES['fileField']['tmp_name'] != "") {   
    //$details = mysql_real_escape_string($_POST['details']);
        $newname = "$askeru23.jpg";
        move_uploaded_file($_FILES['fileField']['tmp_name'], "users_fav/".$_GET['id']."/$newname");
    }
}
HTML form:
<form id="imguploader" method="post" action="" enctype="multipart/form-data">
<label style="font-size:22px; color:#666; font-weight:bold; margin-top:50px; width:100%; height:50px; padding-top:50px;">Upload Photo</label><br  /><br />
<?php echo $usersupload; ?>
<input type="hidden" name="askeruim" id="askeru"  value="<?php echo $askeru23; ?>"/><br  />
<input type="hidden" value="<?php echo $u_id; ?>" name="u_id_im"  />
<input type="file" name="fileField" id="fileField" />
<input type="submit" name="submit" id="closethebox" class="submit"  value="UPLOAD" />
</form>
jQuery code:
$(function(){
    $('#imguploader').on('submit', function(e){
        // prevent native form submission here
        e.preventDefault();
        // now do whatever you want here
        $.ajax({
            type: $(this).attr('method'), // <-- get method of form
            url: $(this).attr('action'), // <-- get action of form
            data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
            beforeSend: function(){
            },
            success: function(data){
            }
        });
    });
});
As a side note, the AJAX code is within a document ready function.
Could someone please advise on this?
Thanks
 
     
     
    