Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/08/2009, 13:20
Avatar de zornak
zornak
 
Fecha de Ingreso: septiembre-2008
Ubicación: Toledo
Mensajes: 96
Antigüedad: 15 años, 8 meses
Puntos: 3
Respuesta: Javascript y php error...

A parte de que no entiendo como va...

Bueno, te comento, me e bajado el jquery ese y lo e renombrado a jquery.js (me venia en formato js)

mi index.html:

Código html:
Ver original
  1. <head><title>Ejemplo de uso de jquery por paridin </title>
  2. <!-- Incluimos la libreria jquery -->
  3. <script languaje="javascript" type="text/javascript" src="jquery.js"></script>
  4. <script languaje="javascript" type="text/javascript" >
  5. <!-- Crearemos la funcion que tu utilizas -->
  6.  
  7. function cargarPHP(){
  8.  
  9.              var nombre = document.getElementById('nombre');
  10.              var edad =  document.getElementById('edad');
  11.              var selec = document.getElementById('selec');
  12.  
  13.     $.ajax( {
  14.         async:true,
  15.         dataType: "html",
  16.         type: "POST",
  17.         url: "phpresultado.php",
  18.         data: "nombre="+nombre+"&edad="+edad+"&selec="+selec,
  19.        global: true,
  20.        ifModified: false,
  21.        processData:true,
  22.        contentType: "application/x-www-form-urlencoded",
  23.        success: function(datos){
  24.            $("#resultado").html(datos);
  25.         }
  26.     });
  27.  
  28.  
  29. </head>
  30. <h1> mostrar resultado de php en una etiqueta</h1>
  31. Usaremos la etiqueta DIV sin embargo debe resultar en cualquier etiqueta
  32.  
  33. <form name="form1" id="form1" action="#" method="post" >
  34. nombre <input type="text" name="nombre" id="nombre" /> <br />
  35. edad  <input type="text" name="edad" id="edad" /> <br />
  36. mostrar edad o nombre:
  37. <input type="radio" name="selec" value="nombre" id="selec"/> Nombre
  38. <input type="radio" name="selec" value="edad" id="selec"/> edad
  39.  
  40. <input type="button" name="boton" value="Cargar resultado del php" onclick="cargarPHP()" />
  41. </form>
  42.  
  43.  
  44. <div id="resultado">Aqui cambiara al hacer click del link</div>
  45.  
  46.  
  47. </body>
  48. </html>

phpresultado.php

Código php:
Ver original
  1. <?
  2.  
  3. if($_POST['selec'] == 'nombre'){
  4. echo "Tu nombre es :" . $_POST['nombre'] ;
  5. }else{
  6. echo "Tu edad es :" . $_POST['edad'] ;
  7. }
  8.  
  9.  
  10. ?>