Search code examples
phpwordpresscustomizationcustom-post-type

Image is not passing with serialize formdata on ajax request


    jQuery(document).ready(function(){
    jQuery('#fupForm').on('submit', function(e){
        e.preventDefault();
        var formdata = jQuery("#fupForm").serialize()
        jQuery.ajax({
              url: ajaxurl,
              data : {
                     formdata, 
                     action:'my_ajax_callback_function'
                    },
              type: "POST",
              beforeSend: function(){
                jQuery('#fupForm').css("opacity",".5");
            },
              success: function(response){
                  alert(response);
                  jQuery('#fupForm').css("opacity","");
              } 
        });
    });
});
jQuery(document).ready(function($) {
    jQuery("#datepicker").datepicker();
});
  function img_pathUrl(input){
    jQuery('#img_url')[0].src = (window.URL ? URL : webkitURL).createObjectURL(input.files[0]);
}

I'm just printing the complete formdata using print_r() in my function.php but it's not showing the image name


Solution

  • Use FormData() instead of serialize() method.

    var formData = new FormData(this);