How to use FormData for AJAX file upload?

后端 未结 9 1361
不思量自难忘°
不思量自难忘° 2020-11-21 06:13

This is my HTML which I\'m generating dynamically using drag and drop functionality.

9条回答
  •  余生分开走
    2020-11-21 06:56

    $(document).ready(function () {
        $(".submit_btn").click(function (event) {
            event.preventDefault();
            var form = $('#fileUploadForm')[0];
            var data = new FormData(form);
            data.append("CustomField", "This is some extra data, testing");
            $("#btnSubmit").prop("disabled", true);
            $.ajax({
                type: "POST",
                enctype: 'multipart/form-data',
                url: "upload.php",
                data: data,
                processData: false,
                contentType: false,
                cache: false,
                timeout: 600000,
                success: function (data) {
                    console.log();
                },
            });
        });
    });
    

提交回复
热议问题