Ver Mensaje Individual
  #4 (permalink)  
Antiguo 20/06/2008, 16:04
Avatar de gepd
gepd
 
Fecha de Ingreso: diciembre-2007
Mensajes: 142
Antigüedad: 16 años, 5 meses
Puntos: 6
Respuesta: ayuda con ajax y php

creo que entendi algo, prueba con ésto

éste seria tu formulario
Código:
<!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>Verifica Equipo</title>
<script>
function nuevoAjax(){
    var objetoAjax=false;
    
    try{
        objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e) {
        try {
            objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }catch (E) {
            objetoAjax = false;
        }
    }
    
    if (!objetoAjax && typeof XMLHttpRequest!='Error Indefinido') {
        objetoAjax = new XMLHttpRequest();
    }
    return objetoAjax;
}

function verificaEquipo (idEquipo){
    var ajax = nuevoAjax();
    
    ajax.open("POST","verificaEquipo.php",true);
    ajax.onreadystatechange = function(){
        
        if (ajax.readyState == 4){
            respuesta = ajax.responseText;
            if(respuesta == 0){
                alert('error el numero de equipo ingresado es incorrecto');            
                return false;
                
            }else if(respuesta == 1){
                return true;
            }                        
        }
    }
    
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send("idEquipo="+idEquipo);
}
</script>
</head>
<body>
<input type="text" name="id_equipo" onblur="verificaEquipo(this.value);" />
</body>
</html>
éste seria el php que verifica si exíste el equipo
verificaEquipo.php
Código PHP:
<?php 

        
//conexion
        
        
$idEquipo $_POST['idEquipo'];
        
$numero $_SESSION['numero'];
        
            
$sql="SELECT nume_serv,nume_equipo,marc_equipo FROM clientes WHERE nume_serv='$numero' AND nume_equipo = '$idEquipo'";
            
$info=mysql_query($sql$link);
            
$raw mysql_num_rows($info);
            
            if(
$raw 0){
                echo 
1;//todo correcto
            
}else{
                echo 
0;//no hay registros
            
}
?>
una cosa, en el php, he incluido una variable de tipo $_SESSION ya que creo que al ingresar ha esa parte del sistema, puedes crear una variable con ese dato, para no tener que estar ejecutando más consultas, de todos modos si crees que puedes hacer una consulta con mayor resultado, lo principal que hice aqui fué mostrarte como se puede obtener lo que entendí que quieres


saludos