Hola, tengo el siguiente codigo javascript
:
Código Javascript
:
Ver original<!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">
function ajax(){
var tmp;
if(window.XMLHttpRequest){
tmp=new XMLHttpRequest();
}else{
tmp=new ActiveXObject("Microsoft.XMLHTTP");
}
return tmp;
}
function gos(){
ajax=ajax();
ajax.onreadystatechange=function(){
if(ajax.state==200 && ajax.readyState==4){
alert(ajax.responseText);
document.getElementsByTagName('div')[0].innerHTML=ajax.responseText;
}else{
document.getElementsByTagName('div')[0].innerHTML='Loading...';
}
}
ajax.open('POST','recibir.php',true);
ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
ajax.send('info='+document.getElementById('cosa').value);
}
</script>
</head>
<body>
<input type="text" id="cosa" />
<input type="button" onclick="gos();" />
<br />
<div>
</div>
</body>
</html>
Y en el archivo php
Código PHP:
Ver original<?php
print $_POST['info'].'<br />Funciona!!!'
?>
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?