发新帖

[web前端] jQuery ajax 提交文件

零下一度 2019-8-5 1059
<!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: "url",
            type: "post",
            data: form,
            processData: false,
            contentType: false,
            success: function(data) {
                console.log(data);
            },
            error: function(e) {
                console.log(e);
            }
        });
    }
    </script>
</body
</html>


最新回复 (0)
返回
零下一度
主题数
931
帖子数
0
注册排名
1