PageSourceSearch

https://www.elindependiente.com.ar/toba_3.4/js/basicos/ajax_respuesta.js?av=3.4.8

js elindependiente.com.ar collected 2026-10-02 10:04:31 UTC 2,953 bytes, 102 lines download raw bytes

1/**
2 * @class Clase estatica para el manejo de una respuesta AJAX
3 * @constructor
4 **/
5function ajax_respuesta(modo) {
6	this._modo = modo;
7	this._contexto = null;
8	this._respuesta_plana = '';
9}
10
11ajax_respuesta.prototype.constructor = ajax_respuesta;
12
13	/**
14	 * @private
15	 */	
16	ajax_respuesta.prototype.set_callback = function(clase, funcion) {
17		if (typeof clase != 'object') {
18			throw 'AJAX DATOS: Se requiere que el 3er parámetro sea un objeto';
19		}
20		if (typeof funcion != 'function') {
21			throw 'AJAX DATOS: Se requiere que el 4to parámetro sea un función javascript válida';
22		}
23		this._clase = clase;
24		this._funcion = funcion;
25	};
26	
27	/**
28	 * @private
29	 */		
30	ajax_respuesta.prototype.set_contexto = function(contexto) {
31		this._contexto = contexto;
32	};
33	
34	/**
35	 * @private
36	 */		
37	ajax_respuesta.prototype.set_nodo_html = function(nodo) {
38		if (nodo !== null && typeof nodo == 'object' && isset(nodo.innerHTML)) {
39			this._nodo_html = nodo;
40		} else {
41			throw 'AJAX HTML: Se requiere que el 3er parámetro sea un nodo html válido';
42		}
43	};
44	
45	/**
46	 * Retorna parte de una respuesta a un pedido de datos plano (sin encoding)
47	 */
48	ajax_respuesta.prototype.get_cadena = function(clave) {
49		var string_clave = '<--toba:' + clave + '-->';
50		var inicial = this._respuesta_plana.indexOf(string_clave);
51		if (inicial != -1) {
52			inicial = inicial + string_clave.length;
53			var fin = this._respuesta_plana.indexOf('<--toba', inicial);
54			if (fin == -1) {
55				fin = this._respuesta_plana.length;
56			}
57			return this._respuesta_plana.substr(inicial, fin-inicial);
58		} else {
59			return null;
60		}
61	};
62		
63	/**
64	 * @private
65	 */		
66	ajax_respuesta.prototype.recibir_respuesta = function(response) {
67		try {
68			switch (this._modo) {
69				case 'D':
70					var parametro; 
71					//-- Comunicación de datos codificados con JSON
72					if (response.responseText !== '') {
73						parametro = JSON.parse(response.responseText);
74					} else{
75						parametro = '';
76					}
77					this._funcion.call(this._clase, parametro, this._contexto);
78					break;
79				case 'H':
80					//-- Comunicación de HTML
81					this._nodo_html.innerHTML = response.responseText;
82					break;
83				case 'P': 
84					this._respuesta_plana = response.responseText;
85					//-- Comunicación de información plana
86					this._funcion.call(this._clase, this, this._contexto);
87					break;		
88			}			
89
90		} catch (e) {
91			var	componente = "<textarea id='displayMore' class='ef-input-solo-lectura' cols='40' rows='35' readonly='true' style='display:none;'>" + response.responseText + '</textarea>';
92			var error = 'Error en la respuesta.<br>'  + 'Error JS:<br>' + e  +  '<br>Mensaje Server:<br>' +
93					"<a href='#' onclick='toggle_nodo(document.getElementById(\"displayMore\"));'>Mas</a><br>" + componente
94					+ '<br><br>' + 'Ver el log del sistema para más información';
95			
96			notificacion.limpiar();
97			notificacion.agregar(error);
98			notificacion.mostrar();
99		}
100	};
101	
102toba.confirmar_inclusion('basicos/ajax_respuesta');

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.