chciałem sobie napisać bibliotekę AJAX-a
i wszystko jest OK - poza tym, że w jednej i tylko w jednej (akurat nie o IE chodzi, a o SeaMonkey) nie działa

chodzi o fragment

  1. this.xmlHttp.onreadystatechange = function()
  2. {
  3. tmpObj.getResponse();
  4. }


nie mam pojęcia co i jak zrobić aby w SM zaskoczyło

Biblioteka wygląda tak

  1. function Ajax ()
  2. {
  3. this.xmlHttp = false;
  4. this.ajaxResult = 0;
  5. this.dataStr = false;
  6. this.requestResult;
  7. this.paramLen = 0;
  8. this.errorTxt ='no error';
  9. function createXmlHttpRequestObject(request)
  10. {
  11. if(!request || typeof request=='undefined')
  12. {
  13. try
  14. {
  15. request = new XMLHttpRequest();
  16. }
  17. catch(e)
  18. {
  19. var XmlHttpVersions = new Array(
  20. "MSXML2.XMLHTTP.7.0",
  21. "MSXML2.XMLHTTP.6.0",
  22. "MSXML2.XMLHTTP.5.0",
  23. "MSXML2.XMLHTTP.4.0",
  24. "MSXML2.XMLHTTP.3.0",
  25. "MSXML2.XMLHTTP",
  26. "Microsoft.XMLHTTP");
  27. for (var i=0; i<XmlHttpVersions.length && !request; i++)
  28. {
  29. try
  30. {
  31. request = new ActiveXObject(XmlHttpVersions[i]);
  32. }
  33. catch (e)
  34. {
  35.  
  36. }
  37. }
  38. }
  39. }
  40. return request;
  41. };
  42.  
  43. function encodeDataComponents(dataComponents)
  44. {
  45. var dataString = ' ';
  46. if(!dataComponents || typeof dataComponents == 'undefined')
  47. {
  48. return dataString;
  49. }
  50. if(typeof dataComponents.elements == 'undefined')
  51. return encodeURI(dataString+dataComponents);
  52. var params=dataComponents.elements;
  53. this.paramLen = params.length;
  54. if(this.paramLen==0)
  55. {
  56. return dataString;
  57. }
  58.  
  59. for(n=0;n<this.paramLen;n++)
  60. {
  61. if(params.elements[n].type=='checkbox')
  62. {
  63. dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].checked);
  64. }
  65. else if(params.elements[n].type=='radio')
  66. {
  67. if(params.elements[n].checked)
  68. {
  69. dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].value);
  70. }
  71. }
  72. else if(params.elements[n].type=='select-multiple')
  73. {
  74. for(i=0; i<params.elements[n].options.length; i++)
  75. {
  76. dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].options[m].value)
  77. }
  78. }
  79. else
  80. {
  81. dataString += "&"+ params.elements[n].name + "=" + encodeURIComponent(params.elements[n].value);
  82. }
  83. }
  84. return dataString;
  85. };
  86.  
  87.  
  88.  
  89. this.getAjax = function()
  90. {
  91. this.xmlHttp = createXmlHttpRequestObject(this.xmlHttp);
  92. this.ajaxResult = 2;
  93. if(!this.xmlHttp)
  94. this.ajaxResult = -11;
  95. return this.xmlHttp;
  96. };
  97.  
  98. this.getRequestData = function(data)
  99. {
  100.  
  101. this.dataStr = encodeDataComponents(data);
  102. this.ajaxResult = 3;
  103. if(!this.dataStr)
  104. this.ajaxResult = -12;
  105. };
  106.  
  107. this.sendRequest = function(url,data,method,asynchro)
  108. {
  109. this.getAjax();
  110. if(this.ajaxResult==2)
  111. {
  112. if(method!='POST' && method!='GET')
  113. method='GET';
  114. if(asynchro != true && asynchro != false)
  115. asynchro = true;
  116. this.getRequestData(data);
  117. if(this.ajaxResult==3)
  118. {
  119. if(method == 'GET')
  120. {
  121. var urlSend = url + this.dataStr;
  122. var sendetVar = null;
  123. }
  124. else
  125. {
  126. var urlSend = url;
  127. var sendetVar = this.dataStr;
  128. }
  129. try
  130. {
  131.  
  132. this.xmlHttp.open(method, urlSend, asynchro);
  133.  
  134. this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
  135. if(this.paramLen>0)
  136. this.xmlHttp.setRequestHeader("Content-length",this.paramLen);
  137. var tmpObj = this;
  138. this.xmlHttp.onreadystatechange = function()
  139. {
  140. tmpObj.getResponse();//tu jest problem nie wykonuje się ta funkcja
  141. }
  142.  
  143. this.xmlHttp.send(sendetVar);
  144.  
  145. }
  146. catch(e)
  147. {
  148. this.errorTxt = e;
  149. this.ajaxResult = -1;
  150. }
  151. }
  152. }
  153. else
  154. this.ajaxResult = -2;
  155.  
  156. };
  157. this.action = function(){};
  158. this.getResponse = function()
  159. {
  160. if (this.xmlHttp.readyState == 4)
  161. {
  162. if (this.xmlHttp.status == 200)
  163. {
  164. var tmp = this;
  165. this.requestResult = this.xmlHttp.responseText;
  166. tmp.action();
  167. this.ajaxResult=1;
  168. }
  169. else
  170. this.ajaxResult = -22;
  171. }
  172. else
  173. this.ajaxResult=-23;
  174. };
  175. this.getAjaxResult = function()
  176. {
  177. return this.ajaxResult;
  178. };
  179. this.getRequestResult = function()
  180. {
  181. return this.requestResult;
  182. };
  183. this.getErrorTxt = function()
  184. {
  185. return this.errorTxt;
  186. };
  187.  
  188. }


a jej użycie tak

  1. var url ='http://localhost/projekt/index.php?action=action1';
  2. var ajaxObj = new Ajax();
  3. ajaxObj.sendRequest(url,'','GET',false);
  4. var ajaxRetVal = ajaxObj.getAjaxResult();
  5. if(ajaxRetVal==1)
  6. {
  7.  
  8. var ajaxRet = ajaxObj.getRequestResult();
  9. //i tutaj z rezultatem mozna zrobić co się chce
  10. }


rozwiązałem ten problem
teraz działa wszędzie (sprawdzone pod SM, FF, IE, Operą)

podczas użycia nie należy pobierać tego co zwróciło żądanie za pomocą funkcji a bezpośrednio
czyli zamiast

var ajaxRet = ajaxObj.getRequestResult();

ma być

var ajaxRet = ajaxObj.xmlHttp.responseText;

czemu tak jest - nie mam pojęcia, najważniejsze, że działa