I'm using this code to upload a simple image file.
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" onchange="this.form.submit();"/>
</form>
Then I have an upload.php file that is working very good. Now I want to use jQuery post or ajax to upload the image and show it on the screen without refreshing the page. I've changed the code for this:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
</form>
I've add this to my javascript file:
$("form#formUpload").submit(function() {
$.post('upload.php',$("#formUpload").serialize(), function(data) {
}).done(function() {
});
});
But nothing happens. I know that I don't have a submit input to get inside of the method that contents the $post. I've tried with a trigger into a hidden submit button but nothing seems to work. Does anyone can help to resolve this?