JQuery ajax提交form表单实现文件上传

<!DOCTYPE html>
<html>


<head>
    <title></title>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>


<body>
    <form id="tf">
        <input type="file" name="file" />
        <input type="text" name="username" />
        <input type="button" value="提" οnclick="test();" />
    </form>
    <script type="text/javascript">
    function test() {
        var form = new FormData(document.getElementById("tf"));
        $.ajax({
            url: "http://192.168.10.133:8080/ktl/resource/getSourceData",
            type: "post",
            data: form,
            processData: false,
            contentType: false,
            success: function(data) {
                console.log(data);
            },
            error: function(e) {
                console.log(e);
            }
        });
    }
    </script>
</body>


</html>


作者:lihao_李浩
链接:https://www.jianshu.com/p/775cce61bfe5
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值