I'm creating an ajax upload file. I have written my upload code using PHP and it works fine. The problem is when I use $.ajax{}. The form data cannot be received by my upload.php. Here is my code.
function pleaseUpload(){
$(document).ready(function(){
//var fd=new FormData($("form#form_upload_1"));
var fd = new FormData();
fd.append( "file", $("#edit_first [type=file]")[0].files[0]);
fd.append( "hid", $("#form_upload_1 [type=hidden]").val());
alert(fd);
$("#image_1").html("");
$.ajax( {
type: 'POST',
url: 'save_picture.php',
data: fd,
processData: false,
contentType: false,
cache: false,
success: function(data){
$("#image_1").html(data);
}
});
});
}
<form id='form_upload_1' enctype='multipart/form-data' name='form_upload_1' method='post' action=''>
<div id='edit_first' class='upload_button_wrapper'>
<input id='edit_first' class='upload_button' type='file' onchange='pleaseUpload()' name='file'/>
<input type='hidden' name='hid' value="first" />
</div>
</form>