<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax测试导入文件</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<input type="file" id="file">
<button onclick="submit()">请求</button>
<script>
    function submit() {
        let data = new FormData()
        let file = $("#file")
        file = file[0].files[0]
        console.log(file)
        // return
        data.append("file",file);
        $.ajax({
            url: "http://localhost:48080/admin-api/insur/org-info/import-excel",
            type: "POST",
            data: data,
            headers: {
                Authorization: "Bearer 5a09bb60e15549c69d3f5fdd34362db0",
                'tenant-id': 1
            },
            async: false,
            cache: false,
            withCredentials: true,
            // 数据不需要编码
            contentType: false,
            // 数据对象不需要转换成键值对格式
            processData: false,
            beforeSend: function() {
                console.log("beforeSend")
            },
            complete: function() {
                console.log("complete")
            },
            success: function (data) {
                console.log("success")
                console.log(data)
            },
            error: function(data) {
                console.error(data)
            }
        })
    }
</script>
</body>
</html>

 

最后修改于 2023-03-06 17:46:52
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇