jQuery - 如何从表单提交`post`` multipart / form-data`并获得你的函数? [英] jQuery - how to submit a `post` `multipart/form-data` from a form and get your function called?

查看:362
本文介绍了jQuery - 如何从表单提交`post`` multipart / form-data`并获得你的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < form method =POSTid =form_uploadenctype =multipart / form-dataaction =./ dev.html> 
< fieldset>
<图例>
名称:
< / legend>
< input type =textclass =requiredname =file_name/>
< / fieldset>
< fieldset>
<图例>
档案:
< / legend>
< input type =filename =datafile>
< / fieldset>
< input type =submitvalue =上传/>
< / form>

我想通过jQuery ajax工具提交它,而不用页面刷新,并获取我的函数(alert for例如)complition。是否有可能以及如何做这样的事情? (如果可能的话,它可以在IE 6 BTW ... =中工作)解决方案

可能你可以使用 jQuery表单插件。代码将如下所示:

 < script type =text / javascript> 
$(document).ready(function(){
$('#form_upload')。ajaxForm(function(){
alert(Thank you for your upload!);
});
});
< / script>


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

解决方案

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> 

这篇关于jQuery - 如何从表单提交`post`` multipart / form-data`并获得你的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆