Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/01/2010, 10:52
tannyNogales
 
Fecha de Ingreso: enero-2010
Mensajes: 18
Antigüedad: 14 años, 3 meses
Puntos: 0
problema cn onBlur(), no ejecuta ajax 2 veces

hola, tengo un problema q me esta matanto. vecesito verificar la existencia de un campo en el formulario. para empezar mostar un aviso si existe o no, despues hacer otra cosa mas avanzada.

el problema, esque la funion ajax la llama cn el evento onBlur(), peroesta solo se ejecuta 1 vez.. despues no llama el metodo

espero me puedan ayudar:$

el codigo es el siguiente

Código PHP:
<html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Ingresar producto</title>

<
script languaje="Javascript">

function 
objetoAjax(){
    var 
xmlhttp=false;
    try {
        
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (
e) {
        try {
           
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (
E) {
            
xmlhttp false;
          }
    }

    if (!
xmlhttp && typeof XMLHttpRequest!='undefined') {
        
xmlhttp = new XMLHttpRequest();
    }
    return 
xmlhttp;
}

ajax=objetoAjax();

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

function check_Prov(){//tieneque arrojar true si el 'probeedor' existe

  
probeedor=document.getElementById("probeedor").value;
   

  
ajax.open("POST""doExist.php",true);
  
  
ajax.onreadystatechange=function() {
  if (
ajax.readyState==4) {
      
check_Provajax.responseText;
      
alert("mensaje "+check_Prov);
  }
  }

  
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

  
ajax.send("probeedor="+probeedor)

    }

</script>




</head>

<body>

<form name="nuevo_Art" action="" onSubmit="">

<label>check prov<input type="text" id="probeedor" onBlur="check_Prov()"></label>
   

</form>

</body>
</html> 
este es el php q mando a llamar

Código PHP:
<?php
function Conect(){                                        
    if (!(
$link=mysql_connect("localhost","root",""))){
        exit();
        }
    if (!
mysql_select_db("empresa",$link)){
        exit();
        }
return 
$link;}

    
$result=mysql_query("select * from proveedor",Conect());
$rutP=$_POST['probeedor'];



function 
doExist_Prov($rutP){
    
    
$doExist_Prov=false;
    
$link=Conect();
    
$result=mysql_query("select * from proveedor",$link);
    while(
$row mysql_fetch_array($result)) {
        if(
$row["rut_P"]==$rutP){
            
$doExist_Prov true;
    
        }
    }
//end while
    
    
if($doExist_Prov){ echo("este rut ya exiete"); }else{ echo("este rut es nuevo"); }
    
//return $doExist_Prov;
    
mysql_free_result($result);
}
//end doExist_Prov()

doExist_Prov($rutP);
//mysql_free_result($result);
?>