400 Bad Request and illegal invocation in wp_ajax based on processData set to false or true

You can upload file using ajax using below code:

First :
Add attributes name="f-form" and id="f-form" in your <form> tag.

After that, In js script, get form data using new FormData() and send to ajax data,

Note : change url: ajax_object.ajaxurl with your ajax url path

jQuery(document).ready(function(e) {
    jQuery('#f-submit').on('click', function(e) {
      e.preventDefault();
      var form = jQuery('#f-form')[0];
      var varform = new FormData(form);
      varform.append("action", "save_flyer");
      SaveFlyer(varform);
    });

    function SaveFlyer(varform) {
        jQuery.ajax({
            type: "POST",
            url: ajax_object.ajaxurl,
            dataType: "JSON",
            data: varform,
            processData: false,
            contentType: false,
            cache: false,
            beforeSend: onLoading,
            success: onSuccesPing,
            crossDomain:true
        });

    }
    function onLoading() {
    }
    function onSuccesPing(data, status) {
        if(data.result == 'true')
        {
            alert('Success!!');
        }
        if(data.result == 'false')
        {
            alert('Fail!!');
        }
    }
  });

Finaly, ajax handel request :

function save_flyer()
{
    $f_title        = $_POST['f-title'];
    $f_validity   = $_POST['f-validity'];
    $f_ID         = $_POST['f-ID'];
    $f_company    = $_POST['f-company'];
    $f_category   = $_POST['f-category'];

    $new_post = array(
        'post_title'    => $f_title,
        'tags_input'    => $f_category,
        'post_status'   => 'publish',       
        'post_type'     => 'soldy-flyer'
    );

    $post_id = wp_insert_post($new_post);
    if($post_id)
    {
    add_post_meta($post_id, 'sf_flyer-id', $f_ID);
    add_post_meta($post_id, 'sf_flyer-company', $f_company);
    add_post_meta($post_id, 'sf_flyer-valid', $f_validity);

        if(empty($_FILES['f-thumbnail']['error'])){
          require_once( ABSPATH . 'wp-admin/includes/image.php' );
          require_once( ABSPATH . 'wp-admin/includes/file.php' );
          require_once( ABSPATH . 'wp-admin/includes/media.php' );

           $attahment_id = media_handle_upload( 'f-thumbnail', $post_id );

          if(!empty($attahment_id))
          { 
             set_post_thumbnail($post_id, $attahment_id);
          }
         }   
         $result1 = 'true';
    }
    else
    {
            $result1= 'false';
    }   

     echo json_encode(array('result'=>$result1));
    die();  
}
add_action('wp_ajax_save_flyer', 'save_flyer');
add_action('wp_ajax_nopriv_save_flyer', 'save_flyer');

let me know if this helps to you.