The following form allows an user to upload an image:
<form id="form" action="upload.php" enctype="multipart/form-data" method="post">
<input type="file" id="file" name="file" onchange="submitForm()">
</form>
I'd like this form to be submitted as soon as the user selectes its file, so in javascript I did
$(document).ready(function(){
$("form").on('submit',function(e){
console.log("It works");
});
});
function submitForm()
{
$('form').submit();
}
Which works!
I know want my user to stay on the current page once he the form is being submitted, I tried to add a call back function as soon as the form is submitted:
function submitForm()
{
$('form').submit(function(e){
e.preventDefault();
});
}
But then my form is not being submitted...
I also would like to know how to get the result of the ajax call?