Ver Mensaje Individual
  #20 (permalink)  
Antiguo 14/04/2008, 04:35
Avatar de ZiTAL
ZiTAL
 
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 20 años, 2 meses
Puntos: 62
Re: Ejemplo Javascript orientado a objetos

Código:
var a = function()
{
	// cargar valores por defecto
    this.make=function(options)
     {
        this.options={
            method:'post',
            url:'',
            parameters:'id=1',
            contentType:'application/x-www-form-urlencoded',
            response:'text',
        }.concat(options || {});
        return this;
     };
    this.xmlHttp=function()
	  {
		  var _xmlHttp;
		  try { _xmlHttp=new XMLHttpRequest();return _xmlHttp; }
		  catch (e) { try { _xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');return _xmlHttp; }
		  catch (e) { try { _xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');return _xmlHttp; }
		  catch (e) { alert('Your browser does not support AJAX!');return false; }}}
	  };
    this.ready=function()
     {     	     	      	
     	if(this.ajax.readyState!=4)
		 {
		  this.options.transition=this.options.transition.toLowerCase();
		 }
		else
		 {
		  this.options.response=this.options.response.toLowerCase();
		  if(this.options.response=='text')
		   {
		    this.response=this.ajax.responseText;
		   }
		  else if(this.options.response=='xml')
		   {
		    this.response=this.ajax.responseXML;
		   }		  
		 }
		return this;   	
     };	  
    this.process=function()
     {
        this.ajax=new this.xmlHttp;
        this.options.method=this.options.method.toUpperCase();
        this.ajax.open(this.options.method,this.options.url+"?"+this.options.parameters,true);
        this.ajax.setRequestHeader("Content-Type", this.options.contentType);
        var oThis=this;
        this.ajax.onreadystatechange=function(){return oThis.ready();} 
        this.ajax.send(this.options.parameters);
        return this;
     };	  
};
// ...
Gracias MaBoRaK, ahora si funciona, no entiendo el porque no de la otra forma pero bueno.

Seguimos preguntando, bueno ya cargo el resultado en la variable:

this.response

lo que me gustaria saber es como trabajar con esa variable fuera de la clase:

Código:
	var b=new a();
	b.make();
	b.process();
	alert(b.response);
ya que esto no funciona, ya que lo hace antes de ejecute el proceso.

Muchas gracias ;)

PD: Sigue sin funcionar en el IE de los cojones :(
__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan