PHP Classes

File: es/ajax.js

Recommend this page to a friend!
  Classes of Eduardo Martos Gómez   iAJAX   es/ajax.js   Download  
File: es/ajax.js
Role: Auxiliary data
Content type: text/plain
Description: Funciones AJAX
Class: iAJAX
Trigger an AJAX request upon an HTML page event
Author: By
Last change:
Date: 17 years ago
Size: 2,337 bytes
 

Contents

Class file image Download
/*********************************************/ /* Script ajax.js */ /* ----------------------------------------- */ /* Autor: Eduardo Martos Gómez. */ /* Correo-e: eduardo.martos.gomez@gmail.com. */ /* Condiciones de uso: citar al autor. */ /* Fecha: 02/11/2006. */ /*********************************************/ /*********************************************************/ /* Función nuevo_ajax () */ /* ----------------------------------------------------- */ /* Crea, inicializa y devuelve un objeto XMLHTTPRequest. */ /*********************************************************/ function nuevo_ajax () { var xmlhttp = false; try { // Creación del objeto ajax para navegadores diferentes a Explorer xmlhttp = new ActiveXObject ("Msxml2.XMLHTTP"); } catch (e) { // o bien try { // Creación del objet ajax para Explorer xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest (); } return xmlhttp; } /*******************************************************/ /* Función get_html () */ /* --------------------------------------------------- */ /* Ejecuta la llamada AJAX y sustituye el contenido de */ /* id_obj por el resultado obtenido. */ /* Evita los problemas de juegos de caracteres y de */ /* caché (en MS Internet Explorer). */ /* Parámetros: */ /* id_obj: identificador del objeto que se modifica. */ /* destino: URL que AJAX llama y cuyo resultado usa. */ /* metodo: get o 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); }