Red de conocimiento informático - Aprendizaje de código fuente - El cuadro de texto pierde el foco y comprueba dinámicamente si el nombre de usuario ya está ocupado.

El cuadro de texto pierde el foco y comprueba dinámicamente si el nombre de usuario ya está ocupado.

Tecnología Ajax.

¡Descarga el código fuente! ¡Aquí no está claro!

Si estás familiarizado con la tecnología javascript y xml, ¡deberás poder leerlo y escribirlo! Te daré un fragmento.

ContentLoader=función(url,onload,onerror,método,params,contentType){

this.req=null;

this.onload=onload;

this.defaultError;

this.loadXMLDoc(url,método,params,contentType);

}

net.ContentLoader.prototype.loadXMLDoc=función(url ,método,params,contentType){

if (!método){

método="GET";

}

si (!contentType &&. método=="POST"){

contentType='application/x-www-form-urlencoded';

}

si (window.XMLHttpRequest){

this.req= new XMLHttpRequest();

} else if (window.ActiveXObject){

this.req=new ActiveXObject("Microsoft.XMLHTTP");

}

si (this.req){

intente{

var loader= this;

this.req.onreadystatechange=function(){

net.ContentLoader.onReadyState.call(loader);

}

this.req.onreadystatechange=function(){

net.ContentLoader.onReadyState.open(método,url,true);

if (contentType){

this.req.setRequestHeader('Content-Type', contentType);

}

this.req.send(params);

} catch (err){

this.onerror.call(this);

}

}

}

}

}

net.ContentLoader.onReadyState=function(){

var req=this.req;

var ready=req.readyState;

if (ready==net.READY_STATE_ COMPLETE){

var .ContentLoader.prototype.defaultError=function(){

alert("¡error al obtener datos!"

+"\n\nreadyState:"+this.req.readyState

+"\nstatus:"+this.req.status

+"\nheaders:"+este.req.

getAllResponseHeaders());

}

Desde aquí puede obtener la imagen de ActiveXObject. Luego puede enviar una solicitud al servidor de forma asincrónica a través de la imagen. La respuesta generará un documento XML. Luego use un script JAVASCRIPT para obtener el contenido XML.

¡Oye! ¡Te deseo éxito!