Tema: Metodo get()
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/02/2016, 06:11
Avatar de bichomen
bichomen
 
Fecha de Ingreso: junio-2003
Ubicación: Barcelona y alrededores, España
Mensajes: 877
Antigüedad: 20 años, 10 meses
Puntos: 2
Respuesta: Metodo get()

Bueno creo que he conseguido algo, pero debería ser más sencillo:

Código HTML:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

<script type="text/javascript">
	
	$(document).ready(function()
	{
   	$("#menu a").each(function()
   	{
      	var href = $(this).attr("href");
      	$(this).attr(
      	{ 
      		href: "#"
      	});
      	
      	$(this).click(function()
      	{
				var ruta = $('#enlace').data("url");  				
				var variables = 0;
				var variable = "";
				var variable_valor = "";
				var argumentos = "";
				var dato = "";
				var dato1 = "";
				
				for (var j = 1; j < 20; j++) 
				{
					dato = "variable" + j;					
									
					if ($("#enlace").data(dato) == null) 
					{
						break						
					}
					else 
					{
						variables++;				
					}
				}
				
				for (var i = 1; i <= variables; i++) 
				{
					dato1 = 'variable' + i;		
					variable = "variable" + i;			
					variable_valor = $("#enlace").data(dato1);
					argumentos += variable +":\"" + variable_valor + "\", "; 					
				}
				
				argumentos = argumentos.slice(0,-2);
         	       	
				$.get(ruta, { argumentos }, function(data) 				
				{
					$("#contenedor").html(data);
				});
      	});
   	});
	});

</script> 

Y aquí el enlace:

Código HTML:
<div id="enlace" data-url="pagina.php" data-variable1="1" data-variable2="1"><a href="#">Pagina</a></div> 

bichomen
__________________
"Se sabe con exactitud, con cuanta imprecisión, se sabe algo"
Linux Registered User #320332

Última edición por bichomen; 23/02/2016 a las 07:41