11 enero, 2010

Codigo para usar AJAX en JavaScript

function Ajax(){
var xmlhttp = false;
try{
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
}catch (e){
try{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch (E){
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function FuncionAjax(){
oAjax = Ajax();
oAjax.open('GET', 'RetornaAlgo.php', true);
oAjax.onreadystatechange = function(){
if (oAjax.readyState == 4){
document.getElementById('Contenedor').innerHTML = oAjax.responseText;
}
}
oAjax.send(null);
}

No hay comentarios: