Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - how to submit a `post` `multipart/form-data` from a form and get your function called?

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...=)

like image 730
Rella Avatar asked Nov 29 '25 23:11

Rella


1 Answers

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> 
like image 194
Glauco Vinicius Avatar answered Dec 01 '25 12:12

Glauco Vinicius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!