jquery上传多图片/多文件方法-复制即用

jquery上传多图片/多文件方法-复制即用
 var file = document.getElementById('files1').files;
                if (file.length == 0) {
                    alert('请上传文件');
                    return false;
                }
                //新建一个FormData对象
                var formData = new FormData();
                //追加文件数据
                for (i = 0; i < file.length; i++) {
                    console.log(file[i]);
                    formData.append("files[" + i + "]", file[i]);
                }
                formData.append("money", money);
                formData.append("postscript", postscript);
                formData.append("type", 0);
                formData.append("token", token);
                $.ajax({
                    url: '/api/Money/goldEntryBank',
                    type: 'post',
                    data: formData,
                    processData: false,
                    contentType: false,
                    dataType: 'JSON',
                    beforeSend: function (XHR) {
                    },
                    complete: function (XHR, textStatus) {
                    },
                    error: function (XHR, textStatus, errorThrow) {
                    },
                    success: function (data, textStatus) {
                        alert(data.msg);
                        if (data.code == 1) {
                            window.location = '/index/index/index';
                        }
                    }
                });
            });


最后编辑于:2020/05/15作者: 牛逼PHP

发表评论