jQuery - how to submit a `post` `multipart/form-da

2020-04-12 03:24发布

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

1条回答
Rolldiameter
2楼-- · 2020-04-12 03:56

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> 
查看更多
登录 后发表回答