图片的异步上传

 function saveUser2() {
            var id = $("#id").val().trim();
            var uname = $("#uname").val().trim();
            var pwd = $("#pwd").val().trim();
            var file = document.getElementById("file").files[0];
            var formData = new FormData();
            formData.append('id', id);
            formData.append('uname', uname);
            formData.append('pwd', pwd);
            formData.append('file', file);

            $.ajax({
                url: "/home/about",
                type: "post",
                data: formData,
                contentType: false,
                processData: false,
                mimeType: "multipart/form-data",
                success: function (data) {
                    console.log(data);
                },
                error: function (data) {
                    console.log(data);
                }
            });
        }

转自:https://www.cnblogs.com/len0031/p/7678499.html
posted @ 2020-01-07 17:14  Ella88  阅读(143)  评论(0编辑  收藏  举报