estuve probando el metodo POST y no me funciona :s
bueno aca dejo la pagina de prueba:
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script type="text/javascript">
/******************* Creacion del Objeto **********************/
var http_request = false;
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
}else{
if (window.ActiveXObject)
{
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
}
/**************************************************************/
function ajax_request(metodo, _URL_, dato)
{
if (http_request) http_request.onreadystatechange = ajax_getData;
http_request.open(metodo, _URL_, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // solo para POST
var URI = "?ajax=" + encodeURI(dato) + "&";
http_request.send(URI);
}
function ajax_getData()
{
if (ajax_ok())
{
// todo ok, recibimos datos
alert(http_request.responseText);
}
}
function ajax_ok()
{
/* Estado :
# 0 (uninitialized)
# 1 (loading)
# 2 (loaded)
# 3 (interactive)
# 4 (complete)
*/
if (http_request.readyState == 4)
{
if (http_request.status == 200) return true;
else alert('Hubo un problema obteniendo los datos.');
}
return false;
}
</script>
</head>
<body>
<form method="post" action="">
<input type="button" value="request" onclick="ajax_request('POST', 'ajax.php', 'lalala')">
</form>
</body>
</html>
y en ajax.php:
Código PHP:
<?
header('Content-Type: text/plain');
if (isset($_GET['ajax'])) echo "GET!!!";
if (isset($_POST['ajax'])) echo "POST!!!!!";
if (!isset($_GET['ajax']) && !isset($_POST['ajax'])) echo "no anda!!!";
?>