/* * Ajax_Class * Copyright (C) 2008 Wallace A. Perini */ var ob_ajax = null;//Variavel Global - Definido como var pois no ajax variavel do tipo "this" ele se perde no retorno function Ajax_Class() { //----------------------------------------- //Variaveis this.tp_retorno = 'TEXT'; //Tratamento do Retorno do AJAX - TEXT | ALERT | PROC this.tp_metodo = 'GET'; //metodo [GET | POST] this.id_conteudo = ''; //id onde ser colocado o conteudo de retorno this.id_loading = ''; //id para fazer o carregando this.mg_alert = ''; //Mensagem de alerta apos processar a pagina this.des_url = ''; // url para acessar a pagina this.is_hitorico = false; // gravar historico das paginas this.is_asc = true; //assincrono this.is_loading = true; // mostrar o carregando this.txt_carregando = 'Carregando...'; // mostrar o carregando this.executa_funcao_retorno = ''; //----------------------------------------- //Construtor this.Create = function() { //Cria o objeto AJAX this.AJAX(); } this.doAjaxReplace = function(responseTextAjax) { responseTextAjax = unescape(responseTextAjax.replace(/\+/g," ")); return responseTextAjax; } //Abre URL via AJAX this.getUrl = function() { //----------------------------------------- //Inicializacoes if (this.id_loading == '') { this.id_loading = this.id_conteudo; } if (this.is_hitorico) { } if (this.is_loading) { doLoading(this.id_loading, this.txt_carregando); } var tp_retorno = this.tp_retorno; var id_conteudo = this.id_conteudo; var mg_alert = this.mg_alert; var id_loading = this.id_loading; var executa_funcao_retorno = this.executa_funcao_retorno; //----------------------------------------- //Inicia a busca pela pagina via ajax ob_ajax.open(this.tp_metodo,this.des_url,this.is_asc); if (this.tp_metodo == 'POST') { ob_ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); } ob_ajax.onreadystatechange = function () { if (ob_ajax.readyState == 4) { if (ob_ajax.status == 200) { doClearLoading(id_loading); switch (tp_retorno) { //Executa com loader internos case 'TEXT': retornaObj(id_conteudo).innerHTML = ob_ajax.responseText; break; case 'ALERT': if (mg_alert != "") alert(mg_alert); break; case 'PROC': //Somente Executa a URL //alert(ob_ajax.responseText); eval(ob_ajax.responseText); break; //Executa com loader internos case 'TEXT_ALERT': if (mg_alert != "") alert(mg_alert); retornaObj(id_conteudo).innerHTML = ob_ajax.responseText; break; } if (executa_funcao_retorno != '') { eval(executa_funcao_retorno); } } } } ob_ajax.send(this.doUrlPost()); } //----------------------------------------- //URL via ajax post this.doUrlPost = function() { if (this.tp_metodo == 'GET') { return null; } else { return getUrlString(); } } //----------------------------------------- //Cria objeto ajax this.AJAX = function() { if (window.XMLHttpRequest) { // Mozilla, Safari,... ob_ajax = new XMLHttpRequest(); if (ob_ajax.overrideMimeType) { ob_ajax.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { ob_ajax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ob_ajax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } } } //Carregando function doLoading(id, txt) { try { retornaObj(id).innerHTML = '