Problema al implementar AJAX dentro de una clase
Publicado por Rafael Chavez (2 intervenciones) el 13/07/2007 03:57:17
Hola, soy nuevo en AJAX y estoy tratando de implementar una clase (objeto) no se como llamarlo en JavaScript para utilizarlo en mis webs sin reescribir el condigo, el problema es que cuando declaro una variable que almacenara el objeto XMLHTTPREQUESTno me reconoce la propiedad ReadyState siendo que si la declaro dentro de la funcion si lo reconioce ademas de que otra de las propiedades si las reconoce, aqui les dejo la parte del codigo y la comento por si es que no me di a entender.
function AJAX(idDiv){
this.content=idDiv; //contiene el nombre del div u objeto q usare para ver la info
this.obj; //el objeto XMLHTTPREQUEST
this.createAjax=nuevoAjax; //CREA UNA INSTANCIA DE XMLHTTPREQUEST
this.openAjax=openAjaxCon ;//abre la conexion AJAX
}
//FUNCION PARA CREAR LA INSTANCIA DE XMLHTTPREQUEST
function nuevoAjax()
{
var xmlhttp=false;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E) { xmlhttp=false; }
}
if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); }
return xmlhttp;
}
//En esta funcion es donde me genera el error, me dice que this.obj.readyState es nulo o
// no es un objeto, pero si en lugar de usar this.obj solo declaro var obj dentro de la funcion
// si realiza todo muy bien ademas si reconoce el valor de this.content.
function openAjaxCon(method,page,values){
var divs=this.content;
this.obj=this.createAjax();
this.obj.open(method,page,true);
this.obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.obj.onreadystatechange=function()
{
if(this.obj.readyState==1){
......
}
}
if(method=="POST")
this.obj.send(values);
.......
}
De antemano les agradesco su tiempo, mil gracias y espero puedan ayudarme.
Saludos.
Rafael Chavez.
function AJAX(idDiv){
this.content=idDiv; //contiene el nombre del div u objeto q usare para ver la info
this.obj; //el objeto XMLHTTPREQUEST
this.createAjax=nuevoAjax; //CREA UNA INSTANCIA DE XMLHTTPREQUEST
this.openAjax=openAjaxCon ;//abre la conexion AJAX
}
//FUNCION PARA CREAR LA INSTANCIA DE XMLHTTPREQUEST
function nuevoAjax()
{
var xmlhttp=false;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E) { xmlhttp=false; }
}
if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); }
return xmlhttp;
}
//En esta funcion es donde me genera el error, me dice que this.obj.readyState es nulo o
// no es un objeto, pero si en lugar de usar this.obj solo declaro var obj dentro de la funcion
// si realiza todo muy bien ademas si reconoce el valor de this.content.
function openAjaxCon(method,page,values){
var divs=this.content;
this.obj=this.createAjax();
this.obj.open(method,page,true);
this.obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.obj.onreadystatechange=function()
{
if(this.obj.readyState==1){
......
}
}
if(method=="POST")
this.obj.send(values);
.......
}
De antemano les agradesco su tiempo, mil gracias y espero puedan ayudarme.
Saludos.
Rafael Chavez.
Valora esta pregunta


0