Fijate si te sirve como orientación:
Código PHP:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
function http(){
if(typeof window.XMLHttpRequest!='undefined'){
return new XMLHttpRequest();
}else{
try{
return new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
alert('Su navegador no soporta AJAX');
return false;
}
}
}
function request(url,callback,params){
var H=new http(),signo;
if(!H)return;
signo=url.indexOf('?')==-1 ? '?' :'&';
H.open('post',url+signo+new Date().getTime(),false);
H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
H.onreadystatechange=function(){
if(H.readyState==4 && H.status == 200){
callback(H.responseText);
H.abort();
H=null;
}
}
var p='';
for(var i in params){
p+='&'+i+'='+encodeURIComponent(params[i]);
}
H.send(p);
}
function verificarDatosAlumno(legajo){
if(legajo == ''){
alert('ingrese el lejajo');
document.getElementById('legajo').focus();
return false;
}else{
request(
'test2.php',legajoDisponible,{'l':legajo}
);
}
}
function legajoDisponible(r){
if(!parseInt(r)){
alert('el lejajo ingresado ya existe');
document.getElementById('legajo').focus();
}else{
alert('ok');
}
}
</script>
</head>
<body>
<input name="legajo" type="text" id="legajo" value="123456"><input name="" type="button" value="verificar" onclick="verificarDatosAlumno(legajo.value)">
</body>
</html>
test2.php:
Código PHP:
<?php
if(isset($_POST['l']) && $_POST['l']=='123456'){
echo 0;
}else{
echo 1;
}
?>