Ver Mensaje Individual
  #4 (permalink)  
Antiguo 13/11/2012, 13:03
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: Enviar y Retornar VARIAS variables entre JQUERY y PHP

Tenes varios errores, debería ser asi (para evitar hacer el form pasé lods valores directamente)

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. </head>
  8. <button id="procesarform">Enviar</button>
  9. <script type="text/javascript">
  10. //<![CDATA[
  11. $(document).ready(function(){
  12. $('#procesarform').click(function() {  
  13. $.post("consultaDatos.php",{
  14.            tipo_prod:'prod_1',
  15.            rango:'rango_1',
  16.            rangoP:'rangoP_1',
  17.            tipo_garantia:'garantia_1',
  18.            financiamiento:'financiamiento_1'
  19.            } ,
  20.            function(data)
  21.            {
  22. //DE ESTA MANERA SI ME FUNCIONA
  23.       alert(data);
  24. //SI QUIERO LEER VARIOS VALORES QUE ENVIO SEPARADOS POR "," DE PHP NO ME LO HACE
  25.            var recoge=data.split(",");
  26.            var t = recoge[0];
  27.            var r = recoge[1];
  28.            var rP = recoge[2];
  29.            var t2 = recoge[3];
  30.            var f = recoge[4];
  31.          alert(t +'-'+r+'-'+rP);
  32.            }//termina FUNTION (data)
  33.        );//termina FUNCION .post
  34.        
  35.   }); // fin $click enviar    
  36.   });
  37. //]]>
  38. </body>
  39. </html>

en tú código, usas
r = recoge[1];
rP = recoge[1];
t = recoge[1];
f = recoge[1];
que es siempre el segundo elemento del array recoge

Y tu php se puede simplificar

Código PHP:
Ver original
  1. <?php
  2. if (isset($_POST['tipo_prod'])){
  3. echo $_POST['tipo_prod'] . ',';
  4. }
  5. if (isset($_POST['rango'])){
  6. echo $_POST['rango'] . ',';
  7. }
  8. if (isset($_POST['rangoP'])){
  9. echo $_POST['rangoP'] . ',';
  10. }
  11. if (isset($_POST['tipo_garantia'])){
  12. echo $_POST['tipo_garantia'] . ',';
  13. }
  14. if (isset($_POST['financiamiento'])){
  15. echo $_POST['financiamiento'];
  16. }
  17. ?>

faltarían posibles validaciones en el php

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

Última edición por emprear; 13/11/2012 a las 13:14