Ajax = function(){ var HTTP = null; //cria o objeto xmlHTTP this.initHTTP = function(){ try{ // Firefox, Opera 8.0+, Safari HTTP = new XMLHttpRequest(); }catch(e){// Internet Explorer try{ HTTP = new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ try{ HTTP = new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ HTTP = null; return false; }//end try }//end try }//end try return true; } //define a função a ser chamada e que receberá a string retornada pelo HTTP this.configAction = function( function_name ){ if( HTTP != null ){ HTTP.onreadystatechange = function(){ if (HTTP.readyState == 4){ if(HTTP.status == 200) { try{ eval( function_name+"(HTTP.responseText);"); }catch(e){ //alert(e.description); }//end try } else { alert(HTTP.statusText); } } } } } //executa a chamada a pagina e retorna o conteudo chamando a função this.callURL = function(URL, function_name){ this.initHTTP(); if( HTTP != null ){ this.configAction(function_name); var d = new Date(); var newURL = URL+"&rand="+d.getTime(); //falha caso nao haja ? HTTP.open("GET",newURL,true); HTTP.send(null); }else{ alert("browser não compativel com ajax"); } } //executa a chamada a pagina e retorna o conteudo chamando a função this.postURL = function(URL, dados, function_name){ this.initHTTP(); if( HTTP != null ){ this.configAction(function_name); var d = new Date(); var newURL = URL+"&rand="+d.getTime(); //falha caso nao haja ? HTTP.open("POST",newURL,true); HTTP.send(dados); }else{ alert("browser não compativel com ajax"); } } }