alcatrazbr
9/15/2016 - 5:53 PM

ajax submit com formdata

ajax submit com formdata

$("#frmCadastro").submit(function(){
    var arrMotoqueiro = [];
    $("input:checkbox[name='chkMoto[]']:checked").each(function(){
      arrMotoqueiro.push($(this).val());
    });
    
    formData.append("arrMotoqueiro[]", arrMotoqueiro);
 		var formData = new FormData($(this)[0]);
    $.ajax({ // create an AJAX call...
        // data: $(this).serialize(), // get the form data
        data: formData,
        type: $(this).attr('method'), // GET or POST
        url: $(this).attr('action'), // the file to call
		cache: false,
		contentType: false,
		processData: false,
        success: function(xhr,status,error) { // on success..
        	$("#ModalItemDetalhe").modal("toggle");
            // $('.msg').html(response); // update the DIV
            // console.debug(xhr);
            // console.debug(status);
            // console.debug(error);
            // $('#frmConsulta').submit();
        },
        error: function(xhr,status,error){
        	console.log(xhr);
        	console.log(error);
        	console.debug(status);
        	var msg = xhr.responseText;
        	msg = $.parseJSON(msg);
        	$("#edt-retorno").removeClass('hidden');
        	$("#edt-retorno > #message").text(msg.message);
        }
    });
    return false;
});