3

So currently I have a form like this:

            <form method="POST" id="form_upload" enctype="multipart/form-data" action="./dev.html">
                <fieldset>
                    <legend>
                        Name:
                    </legend>
                    <input type="text" class="required" name="file_name" />
                </fieldset>
                <fieldset>
                    <legend>
                        File:
                    </legend>
                    <input type="file" name="datafile">
                </fieldset>
                <input type="submit" value="Upload" />
            </form>

I want to submit it without page refresing, via jQuery ajax tools and get my function called (alert for example) on complition. Is it possible and how to do such thing? (If it is possible it shall work in IE 6 BTW...=)

Rella
  • 65,003
  • 109
  • 363
  • 636
  • 1
    [What have you tried so far?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) Have you read about the [jQuery `.get()`](http://api.jquery.com/jQuery.get/) and [jQuery `.ajax()`](http://api.jquery.com/jQuery.ajax/) functions? – nnnnnn Oct 28 '11 at 01:15
  • Consider using FormData class as described in http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax – Anton Shchastnyi May 16 '13 at 12:21
  • possible duplicate of [How can I upload files asynchronously with jQuery?](http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery) – keshu_vats Sep 09 '13 at 10:14

1 Answers1

2

Maybe you can use the jQuery Form Plugin. The code will be something like it:

<script type="text/javascript"> 
    $(document).ready(function() { 
        $('#form_upload').ajaxForm(function() { 
            alert("Thank you for your upload!"); 
        }); 
    }); 
</script> 
Glauco Vinicius
  • 2,527
  • 3
  • 24
  • 37