How to use FormData for AJAX file upload?

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

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

9条回答
  •  轮回少年
    2020-11-21 06:58

    $('#form-withdraw').submit(function(event) {
    
        //prevent the form from submitting by default
        event.preventDefault();
    
    
    
        var formData = new FormData($(this)[0]);
    
        $.ajax({
            url: 'function/ajax/topup.php',
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (returndata) {
              if(returndata == 'success')
              {
                swal({
                  title: "Great",
                  text: "Your Form has Been Transfer, We will comfirm the amount you reload in 3 hours",
                  type: "success",
                  showCancelButton: false,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "OK",
                  closeOnConfirm: false
                },
                function(){
                  window.location.href = '/transaction.php';
                });
              }
    
              else if(returndata == 'Offline')
              {
                  sweetAlert("Offline", "Please use other payment method", "error");
              }
            }
        });
    
    
    
    }); 
    

提交回复
热议问题