Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/12/2011, 19:28
morbo198
 
Fecha de Ingreso: febrero-2011
Mensajes: 41
Antigüedad: 13 años, 2 meses
Puntos: 1
Pregunta Recargar con Ajax un solo div con diferentes contenidos

Necesito ayuda para lo siguiente espero y me puedan ayudar les muestro el index y despues el codigo de ajax

Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Recarga de contenido con Ajax</title>
<script src="ajax.js" language="javascript" type="text/javascript"> </script>
</head>
<body>
<a href="#" onclick="recarga(div1,contenido1.html)">AQUI 1</a>
<a href="#" onclick="recarga(div1,contenido2.html)">AQUI 2</a>
<a href="#" onclick="recarga(div1,contenido3.html)">AQUI 3</a>
	
<div id="div1">
</div>

</body>
</html>
lo que quiero hacer esque cuando pulse cada link me recargue difrente contenido en el mismo Div aqui les presento el codigo que estoy utilizando
Código:
function recarga(divid,url)
{

var divid,url,fetch_unix_timestamp;

if(divid == ""){ alert('Error: escribe el id del div que quieres refrescar'); return;}
else if(!document.getElementById(divid)){ alert('Error: el Div ID selectionado no esta definido: '+divid); return;}
else if(url == ""){ alert('Error: la URL del documento que quieres cargar en el div no puede estar vacia.'); return;}



var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); 
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Tu explorador no soporta AJAX.");
return false;
}
}
}

// Timestamp para evitar que se cachee el array GET

fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}

var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;

// llamando al ajax
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}
en la validacion de las variables me marca el segundo error que tengo descrito, este es el error que sale en el alert Error: el Div ID selectionado no esta definido: [object HTMLDivElement] jajaja y no entiendo el porque