0

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?

napstercake
  • 1,815
  • 6
  • 32
  • 57
  • try http://stackoverflow.com/questions/19447435/ajax-upload-image – ariel Feb 18 '14 at 01:35
  • It seems the way to send the form in that way is wrong. So I've found a jquery library call 'jquery.form.min.js' that solve the problem using $(this).ajaxSubmit('OPTIONS') here's a very fancy example here: http://www.sanwebe.com/2012/05/ajax-image-upload-and-resize-with-jquery-and-php – napstercake Feb 19 '14 at 15:35

0 Answers0