Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/05/2009, 12:10
Avatar de pato12
pato12
 
Fecha de Ingreso: septiembre-2007
Ubicación: Salta
Mensajes: 1.620
Antigüedad: 17 años, 6 meses
Puntos: 101
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 original
  1. var XAjax={
  2.     request:false,
  3.     json:false,
  4.     url:false,
  5.     type:'post',
  6.     data:false,
  7.     cache:false,
  8.     success:function(){},
  9.     error:function(){},
  10.     complete:function(){},
  11.     loading:function(){},
  12.     requestHttpVercions:[ "MSXML2.XMLHttp.5.0",
  13.                 "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
  14.                 "MSXML2.XMLHttp","Microsoft.XMLHttp"],
  15.     ajax:function(config){
  16.         for(conf in config){
  17.             if(config[conf]!=''&&config[conf]!==false&&config[conf]!=null||config[conf]!=undefined)
  18.             this[conf]=config[conf];
  19.         }
  20.         _this=this;
  21.         if(!this.requestXMLH()){return this.error("Su navegador no soporta AJAX.",0,0);}
  22.         this.request.onreadystatechange=function(){_this.prosData()};
  23.         this.request.open(this.type,this.getData(), true);
  24.         this.request.send((this.type=='post'?this.postData():null));
  25.  
  26.     },
  27.     requestXMLH:function() {
  28.         if (window.XMLHttpRequest){
  29.             request=new XMLHttpRequest();
  30.         }else if (window.ActiveXObject){
  31.             for (var i = 0; i < this.requestHttpVercions.length; i++) {
  32.                 try {
  33.                     request=new ActiveXObject(this.requestHttpVercions[i]);
  34.                 }catch (error) {
  35.                     request=false;
  36.                 }
  37.             }
  38.         }else{
  39.             request=false;
  40.         }
  41.         return this.request=request;
  42.     },
  43.     getData:function(){
  44.         if(this.type!='get')return this.url;
  45.         if(typeof this.data=="object"){
  46.             var datac=[];
  47.             var n=0;
  48.             for(d in this.data){
  49.                 datac[n]=d+"="+this.data[d];
  50.                 n++;
  51.             }
  52.             if(!this.cache)datac[n]=Math.random()+"="+Math.random();
  53.             data=datac.join('&');
  54.         }else if(typeof this.data!="string")return this.data; else data=this.data;
  55.         return this.url+"?"+data;
  56.     },
  57.     postData:function(){
  58.         if(this.type!='post')return;
  59.         if(typeof this.data=="object"){
  60.             var datac=[];
  61.             var n=0;
  62.             for(d in this.data){
  63.                 datac[n]=d+"="+this.data[d];
  64.                 n++;
  65.             }
  66.             if(!this.cache)datac[n]=Math.random()+"="+Math.random();
  67.             data=datac.join('&');
  68.         }else if(typeof this.data!="string")return this.data; else data=this.data;
  69.             this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  70.             return data;
  71.     },
  72.     prosData:function(){
  73.         if(this.request.readyState==1){this.loading();
  74.         }else if (this.request.readyState == 4) {
  75.             if (this.request.status == 200) {
  76.                 var data = this.json?eval('('+this.request.responseText+')'):this.request.responseText;
  77.                 this.success(data,this.request.status,this.request.readyState);
  78.                 this.complete(data,this.request.status,this.request.readyState);
  79.                 return;
  80.             } else {
  81.                 this.error('URL invalida',this.request.status,this.request.readyState);
  82.             }
  83.         }
  84.     }
  85. };
  86. function ajax(type,url,data){
  87.     XAjax.ajax({
  88.         type:type,
  89.         url:url,
  90.         json:true,
  91.         data:data,
  92.         success:function(data){
  93.             alert(data.alerta);
  94.         }
  95.     });
  96. }
y lo ejecuto haci:
Código html:
Ver original
  1. <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
__________________
Half Music - www.halfmusic.com

Última edición por GatorV; 11/05/2009 a las 11:15