Hola,
Estoy desarrollando una funcion para mandar ajax.
Anda bien pero........ me ejecuta la funcion 2 veses.
Este es el codigo:
Código javascript
:
Ver originalvar XAjax={
request:false,
json:false,
url:false,
type:'post',
data:false,
cache:false,
success:function(){},
error:function(){},
complete:function(){},
loading:function(){},
requestHttpVercions:[ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp","Microsoft.XMLHttp"],
ajax:function(config){
for(conf in config){
if(config[conf]!=''&&config[conf]!==false&&config[conf]!=null||config[conf]!=undefined)
this[conf]=config[conf];
}
_this=this;
if(!this.requestXMLH()){return this.error("Su navegador no soporta AJAX.",0,0);}
this.request.onreadystatechange=function(){_this.prosData()};
this.request.open(this.type,this.getData(), true);
this.request.send((this.type=='post'?this.postData():null));
},
requestXMLH:function() {
if (window.XMLHttpRequest){
request=new XMLHttpRequest();
}else if (window.ActiveXObject){
for (var i = 0; i < this.requestHttpVercions.length; i++) {
try {
request=new ActiveXObject(this.requestHttpVercions[i]);
}catch (error) {
request=false;
}
}
}else{
request=false;
}
return this.request=request;
},
getData:function(){
if(this.type!='get')return this.url;
if(typeof this.data=="object"){
var datac=[];
var n=0;
for(d in this.data){
datac[n]=d+"="+this.data[d];
n++;
}
if(!this.cache)datac[n]=Math.random()+"="+Math.random();
data=datac.join('&');
}else if(typeof this.data!="string")return this.data; else data=this.data;
return this.url+"?"+data;
},
postData:function(){
if(this.type!='post')return;
if(typeof this.data=="object"){
var datac=[];
var n=0;
for(d in this.data){
datac[n]=d+"="+this.data[d];
n++;
}
if(!this.cache)datac[n]=Math.random()+"="+Math.random();
data=datac.join('&');
}else if(typeof this.data!="string")return this.data; else data=this.data;
this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
return data;
},
prosData:function(){
if(this.request.readyState==1){this.loading();
}else if (this.request.readyState == 4) {
if (this.request.status == 200) {
var data = this.json?eval('('+this.request.responseText+')'):this.request.responseText;
this.success(data,this.request.status,this.request.readyState);
this.complete(data,this.request.status,this.request.readyState);
return;
} else {
this.error('URL invalida',this.request.status,this.request.readyState);
}
}
}
};
function ajax(type,url,data){
XAjax.ajax({
type:type,
url:url,
json:true,
data:data,
success:function(data){
alert(data.alerta);
}
});
}
y lo ejecuto haci:
Código html:
Ver original<a href="#" onblur="ajax('post','prueba.php',{hola:'si anda!'});">Probar ajax
</a>
Me alerta 2 veses

o mas en ie.
Gracias
Salu2
¿Nadie sabe porque pasa eso?
Solucionado, erra un error tonto

puse
onblur enves de
onclick