19/10/2010, 13:39
|
| | Fecha de Ingreso: julio-2010
Mensajes: 3
Antigüedad: 13 años, 9 meses Puntos: 0 | |
Respuesta: Pasar variables desde JavaScript a un fichero PHP de procesar Formulario. Cita:
Iniciado por JoseTejada Usando Ajax es de esta manera: archivo "formulario.html" Código PHP: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title> <script language="javascript"> var http; function getHTTP(){ var xmlhttp; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { try { xmlhttp = new XMLHttpRequest(); } catch(e) { xmlhttp= false; } } } return xmlhttp; } http=getHTTP(); function enviarDato(){ if(http){ var nombre=document.getElementById("nombre").value; var codigo=document.getElementById("codigo").value; http.open("GET","proceso.php?nombre="+nombre+"&codigo="+codigo); http.onreadystatechange = comunicacionPHP; http.send(null); }else alert("No hay HTTP"); } function comunicacionPHP(){ if(http.readyState == 4) { if(http.status == 200){ rspta = http.responseText; //Aqui va la respuesta del servidor alert(rspta); } } } </script> </head> <body> <form onsubmit="javascript:{return false;}"> Ingresar nombre : <input type="text" name="nombre" id="nombre" /> <input type="hidden" name="codigo" id="codigo" value="12345" /> <br /> <input type="button" onclick="enviarDato()" value="Enviar dato"/> </form> </body> </html> y el otro "proceso.php" Código PHP: <?php $txt = "El nombre enviado por el cliente es : ".$_GET["nombre"]." y el codigo hidden es : ".$_GET["codigo"]; echo $txt; ?> Espero que sirva...suerte |