国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

282 linhas
8.0KB

  1. <!--
  2. //xmlhttp和xmldom对象
  3. var DedeXHTTP = null;
  4. var DedeXDOM = null;
  5. var DedeContainer = null;
  6. var DedeShowError = false;
  7. var DedeShowWait = false;
  8. var DedeErrCon = "";
  9. var DedeErrDisplay = "下载数据失败";
  10. var DedeWaitDisplay = "正在下载数据...";
  11. //获取指定ID的元素
  12. function $DE(id) {
  13. return document.getElementById(id);
  14. }
  15. //gcontainer 是保存下载完成的内容的容器
  16. //mShowError 是否提示错误信息
  17. //DedeShowWait 是否提示等待信息
  18. //mErrCon 服务器返回什么字符串视为错误
  19. //mErrDisplay 发生错误时显示的信息
  20. //mWaitDisplay 等待时提示信息
  21. //默认调用 DedeAjax('divid',false,false,'','','')
  22. function DedeAjax(gcontainer,mShowError,mShowWait,mErrCon,mErrDisplay,mWaitDisplay)
  23. {
  24. DedeContainer = gcontainer;
  25. DedeShowError = mShowError;
  26. DedeShowWait = mShowWait;
  27. if(mErrCon!="") DedeErrCon = mErrCon;
  28. if(mErrDisplay!="") DedeErrDisplay = mErrDisplay;
  29. if(mErrDisplay=="x") DedeErrDisplay = "";
  30. if(mWaitDisplay!="") DedeWaitDisplay = mWaitDisplay;
  31. //post或get发送数据的键值对
  32. this.keys = Array();
  33. this.values = Array();
  34. this.keyCount = -1;
  35. this.sendlang = 'gb2312';
  36. //请求头类型
  37. this.rtype = 'text';
  38. //初始化xmlhttp
  39. //IE6、IE5
  40. if(window.ActiveXObject) {
  41. try { DedeXHTTP = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { }
  42. if (DedeXHTTP == null) try { DedeXHTTP = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { }
  43. }
  44. else {
  45. DedeXHTTP = new XMLHttpRequest();
  46. }
  47. //增加一个POST或GET键值对
  48. this.AddKeyN = function(skey,svalue) {
  49. if(this.sendlang=='utf-8') this.AddKeyUtf8(skey, svalue);
  50. else this.AddKey(skey, svalue);
  51. };
  52. this.AddKey = function(skey,svalue) {
  53. this.keyCount++;
  54. this.keys[this.keyCount] = skey;
  55. svalue = svalue+'';
  56. if(svalue != '') svalue = svalue.replace(/\+/g,'$#$');
  57. this.values[this.keyCount] = escape(svalue);
  58. };
  59. //增加一个POST或GET键值对
  60. this.AddKeyUtf8 = function(skey,svalue) {
  61. this.keyCount++;
  62. this.keys[this.keyCount] = skey;
  63. svalue = svalue+'';
  64. if(svalue != '') svalue = svalue.replace(/\+/g,'$#$');
  65. this.values[this.keyCount] = encodeURI(svalue);
  66. };
  67. //增加一个Http请求头键值对
  68. this.AddHead = function(skey,svalue) {
  69. this.rkeyCount++;
  70. this.rkeys[this.rkeyCount] = skey;
  71. this.rvalues[this.rkeyCount] = svalue;
  72. };
  73. //清除当前对象的哈希表参数
  74. this.ClearSet = function() {
  75. this.keyCount = -1;
  76. this.keys = Array();
  77. this.values = Array();
  78. this.rkeyCount = -1;
  79. this.rkeys = Array();
  80. this.rvalues = Array();
  81. };
  82. DedeXHTTP.onreadystatechange = function() {
  83. //在IE6中不管阻断或异步模式都会执行这个事件的
  84. if(DedeXHTTP.readyState == 4){
  85. if(DedeXHTTP.status == 200)
  86. {
  87. if(DedeXHTTP.responseText!=DedeErrCon) {
  88. DedeContainer.innerHTML = DedeXHTTP.responseText;
  89. }
  90. else {
  91. if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay;
  92. }
  93. DedeXHTTP = null;
  94. }
  95. else { if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay; }
  96. }
  97. else { if(DedeShowWait) DedeContainer.innerHTML = DedeWaitDisplay; }
  98. };
  99. //检测阻断模式的状态
  100. this.BarrageStat = function() {
  101. if(DedeXHTTP==null) return;
  102. if(typeof(DedeXHTTP.status)!=undefined && DedeXHTTP.status == 200)
  103. {
  104. if(DedeXHTTP.responseText!=DedeErrCon) {
  105. DedeContainer.innerHTML = DedeXHTTP.responseText;
  106. }
  107. else {
  108. if(DedeShowError) DedeContainer.innerHTML = DedeErrDisplay;
  109. }
  110. }
  111. };
  112. //发送http请求头
  113. this.SendHead = function()
  114. {
  115. //发送用户自行设定的请求头
  116. if(this.rkeyCount!=-1)
  117. {
  118. for(var i = 0;i<=this.rkeyCount;i++)
  119. {
  120. DedeXHTTP.setRequestHeader(this.rkeys[i],this.rvalues[i]);
  121. }
  122. }
  123.  if(this.rtype=='binary'){
  124.  DedeXHTTP.setRequestHeader("Content-Type","multipart/form-data");
  125. }else{
  126. DedeXHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  127. }
  128. };
  129. //用Post方式发送数据
  130. this.SendPost = function(purl) {
  131. var pdata = "";
  132. var i=0;
  133. this.state = 0;
  134. DedeXHTTP.open("POST", purl, true);
  135. this.SendHead();
  136. //post数据
  137. if(this.keyCount!=-1)
  138. {
  139. for(;i<=this.keyCount;i++)
  140. {
  141. if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
  142. else pdata += "&"+this.keys[i]+'='+this.values[i];
  143. }
  144. }
  145. DedeXHTTP.send(pdata);
  146. };
  147. //用GET方式发送数据
  148. this.SendGet = function(purl) {
  149. var gkey = "";
  150. var i=0;
  151. this.state = 0;
  152. //get参数
  153. if(this.keyCount!=-1)
  154. {
  155. for(;i<=this.keyCount;i++)
  156. {
  157. if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
  158. else gkey += "&"+this.keys[i]+'='+this.values[i];
  159. }
  160. if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
  161. else purl = purl + '&' + gkey;
  162. }
  163. DedeXHTTP.open("GET", purl, true);
  164. this.SendHead();
  165. DedeXHTTP.send(null);
  166. };
  167. //用GET方式发送数据,阻塞模式
  168. this.SendGet2 = function(purl) {
  169. var gkey = "";
  170. var i=0;
  171. this.state = 0;
  172. //get参数
  173. if(this.keyCount!=-1)
  174. {
  175. for(;i<=this.keyCount;i++)
  176. {
  177. if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
  178. else gkey += "&"+this.keys[i]+'='+this.values[i];
  179. }
  180. if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
  181. else purl = purl + '&' + gkey;
  182. }
  183. DedeXHTTP.open("GET", purl, false);
  184. this.SendHead();
  185. DedeXHTTP.send(null);
  186. //firefox中直接检测XHTTP状态
  187. this.BarrageStat();
  188. };
  189. //用Post方式发送数据
  190. this.SendPost2 = function(purl) {
  191. var pdata = "";
  192. var i=0;
  193. this.state = 0;
  194. DedeXHTTP.open("POST", purl, false);
  195. this.SendHead();
  196. //post数据
  197. if(this.keyCount!=-1)
  198. {
  199. for(;i<=this.keyCount;i++)
  200. {
  201. if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
  202. else pdata += "&"+this.keys[i]+'='+this.values[i];
  203. }
  204. }
  205. DedeXHTTP.send(pdata);
  206. //firefox中直接检测XHTTP状态
  207. this.BarrageStat();
  208. };
  209. } // End Class DedeAjax
  210. //初始化xmldom
  211. function InitXDom() {
  212. if(DedeXDOM!=null) return;
  213. var obj = null;
  214. // Gecko、Mozilla、Firefox
  215. if (typeof(DOMParser) != "undefined") {
  216. var parser = new DOMParser();
  217. obj = parser.parseFromString(xmlText, "text/xml");
  218. }
  219. // IE
  220. else {
  221. try { obj = new ActiveXObject("MSXML2.DOMDocument");} catch (e) { }
  222. if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
  223. }
  224. DedeXDOM = obj;
  225. };
  226. //读写cookie函数
  227. function GetCookie(c_name)
  228. {
  229. if (document.cookie.length > 0)
  230. {
  231. c_start = document.cookie.indexOf(c_name + "=")
  232. if (c_start != -1)
  233. {
  234. c_start = c_start + c_name.length + 1;
  235. c_end = document.cookie.indexOf(";",c_start);
  236. if (c_end == -1)
  237. {
  238. c_end = document.cookie.length;
  239. }
  240. return unescape(document.cookie.substring(c_start,c_end));
  241. }
  242. }
  243. return null
  244. }
  245. function SetCookie(c_name,value,expiredays)
  246. {
  247. var exdate = new Date();
  248. exdate.setDate(exdate.getDate() + expiredays);
  249. document.cookie = c_name + "=" +escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString()); //使设置的有效时间正确。增加toGMTString()
  250. }
  251. -->