Ver Mensaje Individual
  #20 (permalink)  
Antiguo 17/01/2011, 11:15
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: envio de datos (6 datos )xmlhttp.open("GET","views/getuser.php?q="+str,tr

Bueno, ahora omitiste el método send... (sólo tenías que agregar eso, no quitar el resto)
Código PHP:
<?php 
if(isset($_POST['var1'])){
$a=$_POST["var1"];
$b=$_POST["var2"];

$suma=$a+$b;
echo 
$suma;
exit;    
}
?>
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
a = document.getElementById("a").value;
b = document.getElementById("b").value;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari


xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp .responseText;
}
}
xmlhttp.open("POST","<?php echo basename($_SERVER['PHP_SELF']) ?>",true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send('var1='+a+'&var2='+b);
}

</script>
</head>
<body>

<h2>AJAX</h2>
<form action="" method="POST">
<input name="a" type="text" id="a">
<input name="b" type="text" id="b">
<div id="myDiv"></div>
<button type="button" onClick="loadXMLDoc()">Request data</button>
<p>Click the button several times to see if the time changes, or if the file is cached.</p>
</form>
</body>
</html>