Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ajax] na localhoscie pod IE dziala na innym serv juz nie..
Forum PHP.pl > Forum > Przedszkole
Gość
Mam pewien problem z ajaxem i IE.. na localhoscie wszystko jest ok.. ale na innym serv poprostu nie tworzy polaczenia.. ;/ ie nie zwraca zadnych bledow nawet.. poprostu nie tworzy polaczenia XMLHttpRequest ;/
Balon
po pierwsze zły dział
po drugie pokazałbyś trochę kodu...
Gość
1. w dziale xml/ajax nie moge tworzyc tematow

2.
ajax.js
  1. /* Simple AJAX Code-Kit (SACK) v1.6.1 */
  2. /* Š2005 Gregory Wild-Smith */
  3. /* www.twilightuniverse.com */
  4. /* Software licenced under a modified X11 licence,
  5. see documentation or authors website for more details */
  6.  
  7. function sack(file) {
  8. this.xmlhttp = null;
  9.  
  10. this.resetData = function() {
  11. this.method = "POST";
  12. this.queryStringSeparator = "?";
  13. this.argumentSeparator = "&";
  14. this.URLString = "";
  15. this.encodeURIString = true;
  16. this.execute = false;
  17. this.requestFile = file;
  18. this.vars = new Object();
  19. this.responseStatus = new Array(2);
  20. };
  21.  
  22. this.resetFunctions = function() {
  23. this.onLoading = function() { };
  24. this.onLoaded = function() { };
  25. this.onInteractive = function() { };
  26. this.onCompletion = function() { };
  27. this.onError = function() { };
  28. this.onFail = function() { };
  29. };
  30.  
  31. this.reset = function() {
  32. this.resetFunctions();
  33. this.resetData();
  34. };
  35.  
  36. this.createAJAX = function() {
  37. try {
  38. this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  39. } catch (e1) {
  40. try {
  41. this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  42. } catch (e2) {
  43. this.xmlhttp = null;
  44. }
  45. }
  46.  
  47. if (! this.xmlhttp) {
  48. if (typeof XMLHttpRequest != "undefined") {
  49. this.xmlhttp = new XMLHttpRequest();
  50. } else {
  51. this.failed = true;
  52. }
  53. }
  54. };
  55.  
  56. this.setVar = function(name, value){
  57. this.vars[name] = Array(value, false);
  58. };
  59.  
  60. this.encVar = function(name, value, returnvars) {
  61. if (true == returnvars) {
  62. return Array(encodeURIComponent(name), encodeURIComponent(value));
  63. } else {
  64. this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
  65. }
  66. }
  67.  
  68. this.processURLString = function(string, encode) {
  69. encoded = encodeURIComponent(this.argumentSeparator);
  70. regexp = new RegExp(this.argumentSeparator + "|" + encoded);
  71. varArray = string.split(regexp);
  72. for (i = 0; i < varArray.length; i++){
  73. urlVars = varArray[i].split("=");
  74. if (true == encode){
  75. this.encVar(urlVars[0], urlVars[1]);
  76. } else {
  77. this.setVar(urlVars[0], urlVars[1]);
  78. }
  79. }
  80. }
  81.  
  82. this.createURLString = function(urlstring) {
  83. if (this.encodeURIString && this.URLString.length) {
  84. this.processURLString(this.URLString, true);
  85. }
  86.  
  87. if (urlstring) {
  88. if (this.URLString.length) {
  89. this.URLString += this.argumentSeparator + urlstring;
  90. } else {
  91. this.URLString = urlstring;
  92. }
  93. }
  94.  
  95. // prevents caching of URLString
  96. this.setVar("rndval", new Date().getTime());
  97.  
  98. urlstringtemp = new Array();
  99. for (key in this.vars) {
  100. if (false == this.vars[key][1] && true == this.encodeURIString) {
  101. encoded = this.encVar(key, this.vars[key][0], true);
  102. delete this.vars[key];
  103. this.vars[encoded[0]] = Array(encoded[1], true);
  104. key = encoded[0];
  105. }
  106.  
  107. urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
  108. }
  109. if (urlstring){
  110. this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
  111. } else {
  112. this.URLString += urlstringtemp.join(this.argumentSeparator);
  113. }
  114. }
  115.  
  116. this.runResponse = function() {
  117. eval(this.response);
  118. }
  119.  
  120. this.runAJAX = function(urlstring) {
  121. if (this.failed) {
  122. this.onFail();
  123. } else {
  124. this.createURLString(urlstring);
  125. if (this.xmlhttp) {
  126. var self = this;
  127. if (this.method == "GET") {
  128. totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
  129. this.xmlhttp.open(this.method, totalurlstring, true);
  130. } else {
  131. this.xmlhttp.open(this.method, this.requestFile, true);
  132. try {
  133. this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  134. } catch (e) { }
  135. }
  136.  
  137. this.xmlhttp.onreadystatechange = function() {
  138. switch (self.xmlhttp.readyState) {
  139. case 1:
  140. self.onLoading();
  141. break;
  142. case 2:
  143. self.onLoaded();
  144. break;
  145. case 3:
  146. self.onInteractive();
  147. break;
  148. case 4:
  149. self.response = self.xmlhttp.responseText;
  150. self.responseXML = self.xmlhttp.responseXML;
  151. self.responseStatus[0] = self.xmlhttp.status;
  152. self.responseStatus[1] = self.xmlhttp.statusText;
  153.  
  154. if (self.execute) {
  155. self.runResponse();
  156. }
  157. self.onCompletion();
  158. self.URLString = "";
  159. break;
  160. }
  161. };
  162.  
  163. this.xmlhttp.send(this.URLString);
  164. }
  165. }
  166. };
  167.  
  168. this.reset();
  169. this.createAJAX();
  170. }
  171.  
  172.  
  173. var ajax = new sack();


test.js
  1. function pokaz_wpis(id){
  2. ajax.setVar('x','q');
  3. ajax.requestFile = 'art,1,'+id;
  4. ajax.method = 'POST';
  5. ajax.onFail = function() {
  6. alert('to sie pokazuje pod ie sic!');
  7. };
  8. ajax.onLoading = function() {
  9.  
  10. };
  11. ajax.onLoaded = function() {
  12.  
  13. };
  14. ajax.onInteractive = function() {
  15.  
  16. };
  17. ajax.onCompletion = function() {
  18.  
  19. if (ajax.responseStatus[0]==200){
  20. alert('wsio ok');
  21. } else {
  22. alert('blad');
  23. }
  24. };
  25. ajax.runAJAX()
  26. return false;
  27. }
quba
a jaki to jest ten inny serwer ?
Gość
problem rozwiazany, cos z przegladarka moja nie tak ;/ w sumie sam nie wiem do konca co nie tak.. bo gdy sprawdzam pod inna to wszystko ok :|
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.