国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.1KB

  1. /**
  2. *
  3. * @version $Id: dedeajax.js 1 22:28 2010年7月20日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2020, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. //xmlhttp和xmldom对象
  10. DedeXHTTP = null;
  11. DedeXDOM = null;
  12. DedeContainer = null;
  13. //获取指定ID的元素
  14. function $(eid) {
  15. return document.getElementById(eid);
  16. }
  17. function $DE(id) {
  18. return document.getElementById(id);
  19. }
  20. //参数 gcontainer 是保存下载完成的内容的容器
  21. function DedeAjax(gcontainer) {
  22. DedeContainer = gcontainer;
  23. //post或get发送数据的键值对
  24. this.keys = Array();
  25. this.values = Array();
  26. this.keyCount = -1;
  27. //http请求头
  28. this.rkeys = Array();
  29. this.rvalues = Array();
  30. this.rkeyCount = -1;
  31. //请求头类型
  32. this.rtype = 'text';
  33. //初始化xmlhttp
  34. if (window.ActiveXObject) {//IE6、IE5
  35. try { DedeXHTTP = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
  36. if (DedeXHTTP == null) try { DedeXHTTP = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
  37. }
  38. else {
  39. DedeXHTTP = new XMLHttpRequest();
  40. }
  41. DedeXHTTP.onreadystatechange = function () {
  42. if (DedeXHTTP.readyState == 4) {
  43. if (DedeXHTTP.status == 200) {
  44. DedeContainer.innerHTML = DedeXHTTP.responseText;
  45. DedeXHTTP = null;
  46. } else DedeContainer.innerHTML = "下载数据失败";
  47. } else DedeContainer.innerHTML = "正在下载数据...";
  48. };
  49. //增加一个POST或GET键值对
  50. this.AddKey = function (skey, svalue) {
  51. this.keyCount++;
  52. this.keys[this.keyCount] = skey;
  53. this.values[this.keyCount] = escape(svalue);
  54. };
  55. //增加一个Http请求头键值对
  56. this.AddHead = function (skey, svalue) {
  57. this.rkeyCount++;
  58. this.rkeys[this.rkeyCount] = skey;
  59. this.rvalues[this.rkeyCount] = svalue;
  60. };
  61. //清除当前对象的哈希表参数
  62. this.ClearSet = function () {
  63. this.keyCount = -1;
  64. this.keys = Array();
  65. this.values = Array();
  66. this.rkeyCount = -1;
  67. this.rkeys = Array();
  68. this.rvalues = Array();
  69. };
  70. //发送http请求头
  71. this.SendHead = function () {
  72. if (this.rkeyCount != -1) { //发送用户自行设定的请求头
  73. for (; i <= this.rkeyCount; i++) {
  74. DedeXHTTP.setRequestHeader(this.rkeys[i], this.rvalues[i]);
  75. }
  76. }
  77. if (this.rtype == 'binary') {
  78. DedeXHTTP.setRequestHeader("Content-Type", "multipart/form-data");
  79. } else {
  80. DedeXHTTP.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  81. }
  82. };
  83. //用Post方式发送数据
  84. this.SendPost = function (purl) {
  85. var pdata = "";
  86. var i = 0;
  87. this.state = 0;
  88. DedeXHTTP.open("POST", purl, true);
  89. this.SendHead();
  90. if (this.keyCount != -1) { //post数据
  91. for (; i <= this.keyCount; i++) {
  92. if (pdata == "") pdata = this.keys[i] + '=' + this.values[i];
  93. else pdata += "&" + this.keys[i] + '=' + this.values[i];
  94. }
  95. }
  96. DedeXHTTP.send(pdata);
  97. };
  98. //用GET方式发送数据
  99. this.SendGet = function (purl) {
  100. var gkey = "";
  101. var i = 0;
  102. this.state = 0;
  103. if (this.keyCount != -1) { //get参数
  104. for (; i <= this.keyCount; i++) {
  105. if (gkey == "") gkey = this.keys[i] + '=' + this.values[i];
  106. else gkey += "&" + this.keys[i] + '=' + this.values[i];
  107. }
  108. if (purl.indexOf('?') == -1) purl = purl + '?' + gkey;
  109. else purl = purl + '&' + gkey;
  110. }
  111. DedeXHTTP.open("GET", purl, true);
  112. this.SendHead();
  113. DedeXHTTP.send(null);
  114. };
  115. } // End Class DedeAjax
  116. //初始化xmldom
  117. function InitXDom() {
  118. if (DedeXDOM != null) return;
  119. var obj = null;
  120. if (typeof (DOMParser) != "undefined") { // Gecko、Mozilla、Firefox
  121. var parser = new DOMParser();
  122. obj = parser.parseFromString(xmlText, "text/xml");
  123. } else { // IE
  124. try { obj = new ActiveXObject("MSXML2.DOMDocument"); } catch (e) { }
  125. if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
  126. }
  127. DedeXDOM = obj;
  128. };