/*******************************************/
/* Script ajax.js */
/* --------------------------------------- */
/* Author: Eduardo Martos Gómez. */
/* e-mail: eduardo.martos.gomez@gmail.com. */
/* License: cite autor's name. */
/* Date: 02/11/2006. */
/*******************************************/
/*************************************************************/
/* Function nuevo_ajax () */
/* --------------------------------------------------------- */
/* Creates, initializes and returns a XMLHTTPRequest object. */
/*************************************************************/
function nuevo_ajax ()
{
var xmlhttp = false;
try
{
// Object creation for navigators different than IE
xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP");
}
catch (e)
{
// o bien
try
{
// Object creation for IE
xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined')
{
xmlhttp = new XMLHttpRequest ();
}
return xmlhttp;
}
/**************************************************/
/* Function get_html () */
/* ---------------------------------------------- */
/* Executes AJAX call and inserts its result into */
/* id_obj container . */
/* This function solves problems relating to */
/* charset and cache (in IE). */
/* Parameters: */
/* id_obj: identifier of the container to be */
/* modified. */
/* destino: target URL for AJAX calls. */
/* metodo: get or post (HTTP). */
/**************************************************/
function get_html (id_obj, destino, metodo)
{
var ajax = false;
var obj = document.getElementById (id_obj);
ajax = nuevo_ajax ();
ajax.open (metodo, destino+"&ms="+new Date().getTime());
ajax.onreadystatechange = function ()
{
if (ajax.readyState == 4 && ajax.status == 200)
{
txt = unescape (ajax.responseText);
txt = txt.replace (/\+/gi, " ");
obj.innerHTML = txt;
}
}
ajax.send (null);
} |