Huyi-23
1/7/2016 - 3:25 PM

Enviar formulario

Enviar formulario

$(".guardar").click(function(){
  var cont = $(this).closest(".cont");
	
	var datos = {};
	
	var error = 0;
	
	cont.find("[name]").each(function(){
		var valor = $(this).val()||$(this).attr("data-val");
		datos[$(this).attr("name")] = valor||"";
		
		if($(this).attr("required") && !valor){
			$(this).focus();
			error = 1;
			return false;
		}
	});
	
	if(error){
		return false;
	}
	
	$.ajax({
    url: "url.php",
		data: datos,
		method: "post",
		dataType: "json",
		success: function(data){
			if(data.estado == 1){
				
			}
		}
	});
	
	return false;
});