Ver Mensaje Individual
  #2 (permalink)  
Antiguo 18/03/2013, 20:20
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Contruir objeto con bucle

Tus datos están en un array, peor los tenés que pasar como un objecto em el $.post

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. $(document).ready(function(){
  10. $('button').click( function (){
  11. var parametros = {};
  12. var datos = [];
  13. datos = document.getElementsByTagName('input');
  14.  
  15. for (var i = 0; i < datos.length; i++) {
  16. parametros[datos[i].name] = datos[i].value;
  17. }
  18. console.log(parametros);
  19.  
  20. $.post("test.php",parametros,
  21. function(data){
  22. alert("Datos recibidos: " + data);
  23.  });
  24.  
  25.    });
  26.  
  27. });
  28. //]]>
  29. </head>
  30. <button>enviar</button>
  31. <form action="#">
  32. <input type="text" name="nombre" value="juan" /><br >
  33. <input type="text" name="run100" value="40" /><br >
  34. </form>
  35. </body>
  36. </html>

test.php

Código PHP:
Ver original
  1. <?php
  2. $respuesta ="";
  3. if($_POST['nombre'] == 'juan'){
  4. $respuesta .= "A ";
  5. }
  6.  
  7. if($_POST['run100'] == '40'){
  8. $respuesta .= "B ";
  9. }
  10. echo $respuesta;
  11. ?>

En mi ejemplo utilicé los tags input de un form para crear el array. luego agregamos al objeto los pares name:value

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.