I want to submit a multipart/form-data
form without leaving my page or reloading using jQuery
and AJAX
. When I submit it with PHP only it does the job well but leaves the page.
HTML:
<form action="" id="myform" method="POST" class="myform" enctype="multipart/form-data">
<input type="file" id="image" name="file">
<input border="4" type="submit" value="submit" id="sumit" name="submit" class="button" />
jQuery:
$(function() {
$('.myform').submit( function() {
$.ajax({
url : 'c_create.php',
type : 'POST',
data : formdata(),
success : function( data ) {
alert('ok');
},
error : function(){
alert('error');
}
});
return false;
});
});
Any help will be greatly appreciated. Thanks in advance. :)