Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/02/2011, 07:52
hechicero0410
 
Fecha de Ingreso: febrero-2011
Ubicación: Pasto
Mensajes: 2
Antigüedad: 13 años, 2 meses
Puntos: 0
Pregunta Gif de precarga sobre clase cargadorContenidos

Hola a todos,

Como sabran la clase cargadorContenidos es extraida de una manual de ajax, la verdad es muy util, sin embargo, en ella no se muestra como colocar una imagen de precarga... si alguien me puede ayudar con ese detalle se los agradeceria. a continuación anexo la clase en mención.

Código Javascript:
Ver original
  1. var net = {
  2.     READY_STATE_UNINITIALIZED: 0,
  3.     READY_STATE_LOADING: 1,
  4.     READY_STATE_LOADED: 2,
  5.     READY_STATE_INTERACTIVE: 3,
  6.     READY_STATE_COMPLETE: 4
  7. };
  8.  
  9. net.CargadorContenidos = function (url, funcion, metodo, parametros, contentType, funcionError) {
  10.     this.url = url;
  11.     this.metodo = metodo;
  12.     this.parametros = parametros;
  13.     this.contentType = contentType;
  14.     this.req = null;
  15.     this.onload = funcion;
  16.     this.onerror = (funcionError) ? funcionError : this.defaultError;
  17.     this.cargaContenidoXML ();
  18. }
  19.  
  20. net.CargadorContenidos.prototype = {
  21.    
  22.     cargaContenidoXML: function () {
  23.         var ie = navigator.userAgent.toLowerCase().indexOf('msie')!=-1;
  24.    
  25.         if (ie) {
  26.             try {
  27.                 this.req = new ActiveXObject ("Msxml2.XMLHTTP");
  28.             }
  29.             catch (e) { // en caso que sea una versión antigua
  30.                 this.req = new ActiveXObject ("Microsoft.XMLHTTP");
  31.             }
  32.         }
  33.         else {
  34.             this.req = new XMLHttpRequest();
  35.         }
  36.         if(this.req) {
  37.             try {
  38.                
  39.                 var loader = this; // imagen del objeto this para utilizarla en el metodo onReadyStateChange
  40.                 loader.req.onreadystatechange = function () {
  41.                     loader.onReadyState.call (loader);
  42.                 }
  43.                 this.req.open (this.metodo, this.url, true);
  44.                 if (this.contentType) {
  45.                     this.req.setRequestHeader("Content-Type", this.contentType);
  46.                 }
  47.                 this.req.send(this.parametros);
  48.             }
  49.             catch (err) {
  50.                 this.onerror.call(this);
  51.             }
  52.         }
  53.     },
  54.    
  55.     onReadyState: function() {
  56.         var req = this.req;
  57.         var ready = req.readyState;
  58.         if (ready == net.READY_STATE_COMPLETE) {
  59.             var httpStatus = req.status;
  60.             if (httpStatus == 200  || window.location.href.indexOf("http") == -1) {
  61.                 this.onload.call(this);
  62.             }
  63.             else {
  64.                 this.onerror.call(this);
  65.             }
  66.         }
  67.     },
  68.    
  69.     defaultError: function() {
  70.         alert (
  71.             "Se ha producido un error al obtener los datos"
  72.             + "\n\nreadyState:"
  73.             + this.req.readyState
  74.             + "\nstatus: "
  75.             + this.req.status
  76.             + "\nheaders: "
  77.             + this.req.getAllResponseHeaders()
  78.         );
  79.     }
  80. }

Última edición por hechicero0410; 15/02/2011 a las 10:22