发布于 4年前

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


<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>
©2020 edoou.com   京ICP备16001874号-3