Lo del escapado puedes resolverlo así:
Código PHP:
<script>
function ajaxClass(URL,method,codePage,data,typeHeader){
var xmlhttp ="";
var contentType = new Array();
contentType[0] = 'text/xml';
contentType[1] = 'text/html';
contentType[2] = 'application/x-www-form-urlencoded';
if(typeof window.XMLHttpRequest!='undefined'){
xmlhttp = new XMLHttpRequest();
}else{
try{
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
alert('Su navegador no soporta AJAX');
return false;
}
}
if(method == "GET"){
var t=data.split('&');
var p='';
for(var i=0,l=t.length;i<l;i++){
var t2=t[i].split('=');
p+='&'+t2[0]+'='+escape(t2[1]);
}
URL = URL+"?"+p;
xmlhttp.open(method,URL,true);
xmlhttp.setRequestHeader('Content-Type',contentType[typeHeader]);
xmlhttp.setRequestHeader('encoding',codePage);
xmlhttp.send(null);
}else if(method == "POST"){
var t=data.split('&');
var p='';
for(var i=0,l=t.length;i<l;i++){
var t2=t[i].split('=');
p+='&'+t2[0]+'='+escape(t2[1]);
}
URL = URL+"?"+p;
xmlhttp.open(method,URL,true);
xmlhttp.setRequestHeader('Content-Type',contentType[typeHeader]);
xmlhttp.setRequestHeader('encoding',codePage);
xmlhttp.setRequestHeader('Content-Type',contentType[2]);
xmlhttp.setRequestHeader('Content-length',data.length);
xmlhttp.send(data);
}else{
alert("Method not Defined.");
}
this.xhr=xmlhttp;
this.addEventListener=function(e,fn,u){
var _this=this;
if(_this.xhr.addEventListener)
_this.xhr.addEventListener(e,fn,u);
else{
_this.xhr['on'+e]=function(){fn.call(_this.xhr,window.event);};
}
}
}
var AJAX = new ajaxClass("t.php","GET","UTF-8","&lasvariables=las Informaciones&lasvariables2=las Informaciones2",1);
AJAX.addEventListener('readystatechange',function(){if(this.readyState==4)document.body.innerHTML=this.responseText;},false);
</script>
De todas maneras no me parece buena idea el generar esos falsos listeners. Lo mejor es usar callbacks, de esta manera:
Código PHP:
<script>
function http(){
if(typeof window.XMLHttpRequest!='undefined'){
return new XMLHttpRequest();
}else{
try{
return new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
alert('Su navegador no soporta AJAX');
return false;
}
}
}
function requestCallbackParam(url,callback,params){
var H=new http();
if(!H)return;
H.open('post',url+'?'+Math.random(),true);
H.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
H.onreadystatechange=function(){
if(H.readyState==4){
callback(H.responseText);
H.onreadystatechange=function(){}
H.abort();
H=null;
}
}
var p='';
for(var i in params){
p+='&'+i+'='+escape(params[i]);
}
H.send(p);
}
requestCallbackParam('t.php',function(r){document.body.innerHTML=r;},{'var1':1,'var2':'hola'});
</script>