Código HTML:
Ver original
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <script type="text/javascript"> var req; var respuesta; function leer_doc(url) { req = false; // Llama objeto XMLHttpRequest if (window.XMLHttpRequest) { req = new XMLHttpRequest(); if (req.overrideMimeType) { req.overrideMimeType('text/xml'); } // Si no funciona intenta utiliar el objeto IE/Windows ActiveX } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } if(req!=null){ req.onreadystatechange = procesarRespuesta; req.open('GET', url, true); req.send(null); } } function autentica(){ usuario = document.getElementById("TXT_MOVI_NDOC").value; url = "existeusuario.php?usuario=" + usuario; leer_doc(url); } function procesarRespuesta(){ respuesta = req.responseXML; var existe = respuesta.getElementsByTagName('existe').item(0).firstChild.data; if (existe=="true") document.getElementById("error").style.visibility = "visible"; else document.getElementById("error").style.visibility = "hidden"; } </script> </head> <body> <form name="form1" method="post" action=""> <input type="text" id="TXT_MOVI_NDOC" onChange="return autentica();"> </form> </body> </html>
Código PHP:
<?php
include('../controllers/conexion.php');
session_start();
$numero_documento = $_GET["usuario"];
header('Content-type: text/xml');
$query = "SELECT MOVI_NDOC
FROM csto_movi
WHERE MOVI_NDOC = '$numero_documento'
";
$result = mysql_query($query) or die(mysql_error());
$fila = mysql_fetch_assoc($result);
if ($numero_documento == $fila['MOVI_NDOC'])
{
echo("<?xml version=\"1.0\" ?><existe>true</existe>");
}
else
{
echo("<?xml version=\"1.0\" ?><existe>false</existe>");
}
?>
gracias por todo.