MozillaPL.org - polskie centrum Mozilli

Główne menu:

[JS w SeaMonkey] Problem z biblioteką ajaxa pod SeaMonkey

Tematy specyficzne dla pakietów SeaMonkey oraz Mozilla Suite

Moderator: Pomocy?!

[JS w SeaMonkey] Problem z biblioteką ajaxa pod SeaMonkey

Postautor: juzwa » 27 lutego 2008, 19:49

Przeglądarka: Mozilla/5.0 (Windows; U; Windows NT 5.1; PL; rv:1.8.1.9) Gecko/20071030 SeaMonkey/1.1.6

piszę sobie - bibliotekę AJAX-a - działa ona wszędzie poza SeaMonkey - za nic w świecie nie wiem dlaczego
chodzi o fragment:
Kod: Zaznacz cały
this.xmlHttp.onreadystatechange = function()
{
tmpObj.getResponse();
}


Działa pod FF, IE (6 i 7), ale pod SM nie chce, siedzę nad tym już sporo czasu i nie wiem czemu, nie rozumiem

jakby ktoś miał jakiś pomysł to byłbym wdzięczny

cała biblioteka wygląda tak

Kod: Zaznacz cały
function Ajax ()
{
this.xmlHttp = false;
this.ajaxResult = 0;
this.dataStr = false;
this.requestResult;
this.paramLen = 0;
this.errorTxt ='no error';
function createXmlHttpRequestObject(request)
{
if(!request || typeof request=='undefined')
{
try
{
request = new XMLHttpRequest();
}
catch(e)
{
var XmlHttpVersions = new Array(
"MSXML2.XMLHTTP.7.0",
"MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
for (var i=0; i<XmlHttpVersions.length && !request; i++)
{
try
{
request = new ActiveXObject(XmlHttpVersions[i]);
}
catch (e)
{

}
}
}
}
return request;
};

function encodeDataComponents(dataComponents)
{
var dataString = ' ';
if(!dataComponents || typeof dataComponents == 'undefined')
{
return dataString;
}
if(typeof dataComponents.elements == 'undefined')
return encodeURI(dataString+dataComponents);
var params=dataComponents.elements;
this.paramLen = params.length;
if(this.paramLen==0)
{
return dataString;
}

for(n=0;n<this.paramLen;n++)
{
if(params.elements[n].type=='checkbox')
{
dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].checked);
}
else if(params.elements[n].type=='radio')
{
if(params.elements[n].checked)
{
dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].value);
}
}
else if(params.elements[n].type=='select-multiple')
{
for(i=0; i<params.elements[n].options.length; i++)
{
dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].options[m].value)
}
}
else
{
dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].value);
}
}
return dataString;
};



this.getAjax = function()
{
this.xmlHttp = createXmlHttpRequestObject(this.xmlHttp);
this.ajaxResult = 2;
if(!this.xmlHttp)
this.ajaxResult = -11;
return this.xmlHttp;
};

this.getRequestData = function(data)
{

this.dataStr = encodeDataComponents(data);
this.ajaxResult = 3;
if(!this.dataStr)
this.ajaxResult = -12;
};

this.sendRequest = function(url,data,method,asynchro)
{
this.getAjax();
if(this.ajaxResult==2)
{
if(method!='POST' && method!='GET')
method='GET';
if(asynchro != true && asynchro != false)
asynchro = true;
this.getRequestData(data);
if(this.ajaxResult==3)
{
if(method == 'GET')
{
var urlSend = url + this.dataStr;
var sendetVar = null;
}
else
{
var urlSend = url;
var sendetVar = this.dataStr;
}
try
{

this.xmlHttp.open(method, urlSend, asynchro);

this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
if(this.paramLen>0)
this.xmlHttp.setRequestHeader("Content-length",this.paramLen);
var tmpObj = this;
this.xmlHttp.onreadystatechange = function()
{
tmpObj.getResponse();//tu jest problem nie wykonuje się ta funkcja
}

this.xmlHttp.send(sendetVar);

}
catch(e)
{
this.errorTxt = e;
this.ajaxResult = -1;
}
}
}
else
this.ajaxResult = -2;

};
this.action = function(){};
this.getResponse = function()
{
if (this.xmlHttp.readyState == 4)
{
if (this.xmlHttp.status == 200)
{
var tmp = this;
this.requestResult = this.xmlHttp.responseText;
tmp.action();
this.ajaxResult=1;
}
else
this.ajaxResult = -22;
}
else
this.ajaxResult=-23;
};
this.getAjaxResult = function()
{
return this.ajaxResult;
};
this.getRequestResult = function()
{
return this.requestResult;
};
this.getErrorTxt = function()
{
return this.errorTxt;
};

}


a jej użycie wygląda tak


Kod: Zaznacz cały
var url ='http://localhost/projekt/index.php?action=action1';
var ajaxObj = new Ajax();
ajaxObj.sendRequest(url,'','GET',false);
var ajaxRetVal = ajaxObj.getAjaxResult();
if(ajaxRetVal==1)
{

var ajaxRet = ajaxObj.getRequestResult();
//i tutaj z rezultatem mozna zrobić co się chce
}
juzwa
 

Wróć do Pakiet SeaMonkey i Mozilla Suite

Kto jest online

Zarejestrowani użytkownicy: Baidu [Spider], Bing [Bot], Google [Bot]

Przejdź do powiązanej strony

Nawigacja:

Stopka: