您的位置:首页 > Web前端 > JQuery

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

2018-07-10 15:04 375 查看
<!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="提" onclick="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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。 阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: