Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/05/2011, 08:30
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 19 años, 10 meses
Puntos: 834
Respuesta: problemas con ajax: Acciones de href cargados con ajax

Probá así:
enlaces.txt:
Código PHP:
<a href="#">decir hola</a> | <a href="#">decir chau</a> | <a href="#">hacer algo</a
loquesea.html:
Código PHP:
<!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>Documento sin t&#237;tulo</title>
<script type="text/javascript">
function 
http(){
    if(
typeof window.XMLHttpRequest!='undefined'){
        return new 
XMLHttpRequest();    
    }else{
        try{
            return new 
ActiveXObject('Microsoft.XMLHTTP');
        }catch(
e){
            
alert('Su navegador no soporta AJAX');
            return 
false;
        }    
    }    
}
function 
request(url,callback,params){
    var 
H=new http();
    if(!
H)return;
    var 
p='';
    for(var 
i in params){
        
p+='&'+i+'='+encodeURIComponent(params[i]);    
    }
    
H.open('get',url+'?'+p+'&'+Math.random(),true);
    
H.onreadystatechange=function(){
        if(
H.readyState==4){
            
callback(H.responseText);
            
H.onreadystatechange=function(){}
            
H.abort();
            
H=null;
        }
    }
    
H.send(null);
}
function 
setEvents(el,type,callback){
    
el[type]=callback;
    
el=null;//eliminamos referencias circulares
}
function 
asignar(r){
    
document.getElementById('rta').innerHTML=r;
    var 
callbacks=[function(){alert('hola');},function(){alert('chau');},function(){alert('¿qué hacemos?');}];
    var 
enlaces=document.getElementById('rta').getElementsByTagName('a');
    for(var 
i=0,o;o=enlaces[i];i++){
        
o.href='javascript:;';
        
setEvents(o,'onclick',callbacks[i]);
    }
    
}
onload=function(){
    
request('enlaces.txt',asignar,{});
}
</script>

</head>

<body>
<div id="rta"></div>
</body>
</html>