Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/10/2009, 10:03
vili86
 
Fecha de Ingreso: septiembre-2009
Mensajes: 281
Antigüedad: 15 años, 5 meses
Puntos: 0
Respuesta: Curioso pero no entiendo pq

Gracias David este es el codigo
Código javascript:
Ver original
  1. <!-- http://www.lawebdelprogramador.com -->
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html>
  4. <head>
  5. <title>AJAX: Número aleatorio</title>
  6.  
  7. <script type="text/javascript">
  8. <!--
  9. var Servidor="aleatorio.php";
  10.  
  11. function Conectar()
  12. {
  13.     if(window.XMLHttpRequest)
  14.     Conexion=new XMLHttpRequest(); //mozilla
  15.     else if(window.ActiveXObject)
  16.     Conexion=new ActiveXObject("Microsoft.XMLHTTP"); //microsoft
  17. }
  18.  
  19. function Contenido()
  20. {
  21.     if(Conexion.readyState!=4) return;
  22.    
  23.  
  24.     if(Conexion.status==200) // Si conexion HTTP es buena !!!
  25.     {
  26.        
  27.             document.getElementById("temp").innerHTML=Conexion.responseText;
  28.     }else{
  29.         document.getElementById("temp").innerHTML=Conexion.status+"-"+Conexion.statusText;
  30.     }
  31.    
  32.     Conexion=false;
  33. }
  34.  
  35. function Solicitud()
  36. {
  37.     if(Conexion) return; // Previene uso repetido del boton.
  38.     Conectar();
  39.     if(Conexion)
  40.     {
  41.        
  42.         Conexion.open("POST",Servidor,true);
  43.  
  44.         Conexion.onreadystatechange=Contenido;
  45.        
  46.     }else
  47.         document.getElementById("temp").innerHTML="No disponible";
  48. }
  49.  
  50.  
  51. window.onload=function()
  52. {
  53.     Solicitud(); // Inicializa el numero aleatorio al cargar la pagina
  54.     document.getElementById("boton").onclick=Solicitud;
  55.  
  56. }
  57. //-->
  58. </script>
  59.  
  60. </head>
  61. <body>
  62. <p>Código que mediante un botón o enlace permite actualizar un valor aleatoriamente.</p>
  63.  
  64. Número aleatorio: <span id="temp">No disponible</span>    <a href="javascript:void(null);" id="texto">generar</a>
  65.  
  66.  
  67. <br /><input type="button" id="boton" value="generar" />
  68. </body>
  69. </html>

Última edición por vili86; 27/10/2009 a las 10:05 Razón: Falto codigo