Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/06/2013, 23:39
Avatar de patilanz
patilanz
 
Fecha de Ingreso: enero-2012
Mensajes: 880
Antigüedad: 13 años, 2 meses
Puntos: 29
Ajax no funciona

Hola, tengo el siguiente codigo javascript:

Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Documento sin título</title>
  6. <script language="javascript">
  7. function ajax(){
  8.     var tmp;
  9.     if(window.XMLHttpRequest){
  10.         tmp=new XMLHttpRequest();
  11.     }else{
  12.         tmp=new ActiveXObject("Microsoft.XMLHTTP");
  13.     }
  14.     return tmp;
  15. }
  16. function gos(){
  17.     ajax=ajax();
  18.     ajax.onreadystatechange=function(){
  19.         if(ajax.state==200 && ajax.readyState==4){
  20.             alert(ajax.responseText);
  21.             document.getElementsByTagName('div')[0].innerHTML=ajax.responseText;
  22.         }else{
  23.             document.getElementsByTagName('div')[0].innerHTML='Loading...';
  24.         }
  25.     }
  26.     ajax.open('POST','recibir.php',true);
  27.     ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
  28.     ajax.send('info='+document.getElementById('cosa').value);
  29.    
  30. }
  31. </script>
  32. </head>
  33.  
  34. <body>
  35. <input type="text" id="cosa" />
  36. <input type="button" onclick="gos();" />
  37. <br />
  38. <div>
  39.  
  40. </div>
  41. </body>
  42. </html>


Y en el archivo php

Código PHP:
Ver original
  1. <?php
  2. print $_POST['info'].'<br />Funciona!!!'
  3. ?>

Antes tambien he usado ajax y funcionaba, pero ahora creo que tengo mal algun detalle y no llega la respuesta simplemete cambie el contenido de la div por Loading...

Que hago mal?