Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/05/2017, 03:06
lightmoon
 
Fecha de Ingreso: septiembre-2015
Mensajes: 21
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Problema retorno array en función

Gracias Alexis88.

Al final lo he solucionado de esta forma:

Código:
function ajax(datos,url,funcion,id){	
 if (confirm('¿Desea proceder?')){ 
	 var valores= new Array();
	 valores[0]=0;
	 valores[1]=0;	
		$.ajax({
			type:'POST',
 			url:url,
 			data:datos,
 			beforeSend: function(){
				 console.log("Espere...");
			 },
 			dataType: "json",
 			success: function (data) {
				console.log(data.success);
				alert(data.success);
				valores[1]= data.id;
				if(valores[1]=='' || valores[1]==null){
					valores[1]=id;
				}
				funcion(valores);
 			},
 			error: function (XMLHttpRequest, textStatus, errorThrown) {
				valores[0]=1;
 			   	alert('ERROR: No se ha podido realizar la acción.');
			   
			   
 			}
		}); //Fin ajax		
	
 }
}
Y en el formulario donde lo llamo:

Código:
<button onclick=\"event.preventDefault();ajax($('#form_trabajador".$array['id_mod_trabajdor']."').serialize(),'index_ajax.php?controlador=gastos/gastos&accion=eliminar_trabajador',quitar,".$array['id_mod_trabajdor'].");\" class='glyphicon glyphicon-remove'/>
El error estaba donde me comentaste, no tuve en cuenta la asincronía de ajax.
Muchas gracias.
Saludos.