Login   Register  
PHP Classes
elePHPant
Icontem

File: en/ajax.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Eduardo Martos Gómez  >  iAJAX  >  en/ajax.js  >  Download  
File: en/ajax.js
Role: Auxiliary data
Content type: text/plain
Description: AJAX script
Class: iAJAX
Trigger an AJAX request upon an HTML page event
Author: By
Last change: Bad translation.
Date: 2006-11-04 04:45
Size: 2,305 bytes
 

Contents

Class file image Download
/*******************************************/
/* 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);
}