欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

自己寫的ajax封裝js類

系統 1838 0
js 代碼
  1. function ?ajax(method,synchronous){ ??
  2. ? ??
  3. ???? this ._httpReq?=? false ;?? /*ajax初始化對象*/ ??
  4. ???? this .method?=?method;?? /*get|post*/ ??
  5. ???? this .syn?=?synchronous;??? /*是否采用異步請求,默認true*/ ??
  6. ? ??
  7. ???? this .url?=? "" ;??? /*提交異步請求的url地址*/ ??
  8. ???? this .resType?=? "" ;?? /*異步請求返回數據類型text|xml*/ ??
  9. ???? this .callback?=? "" ;?? /*異步請求完成后的回滾函數*/ ??
  10. ???? this .loading?=? "" ;?? /*load函數*/ ??
  11. ???? this .content?=? null ;? /*Ajax中send方法的參數*/ ??
  12. ???? this .readystate?=?-1;? /*ajax的請求狀態*/ ??
  13. ???? this .state?=?-1;?? /*http請求響應代碼*/ ??
  14. ? ??
  15. ???? /************?get/set方法開始?***************/ ??
  16. ????? //設置提交異步請求的url地址 ??
  17. ????? this .setUrl?=? function ?(url){ ??
  18. ?????????? this .url?=?url; ??
  19. ?????} ??
  20. ? ??
  21. ????? //設置異步請求返回數據類型text|xml ??
  22. ????? this .setResType?=? function ?(restype){ ??
  23. ?????????? this .resType?=?restype; ??
  24. ?????} ??
  25. ? ??
  26. ????? //設置回滾函數 ??
  27. ????? this .setCallback?=? function ?(func){ ??
  28. ?????????? this .callback?=?func; ??
  29. ?????} ??
  30. ? ??
  31. ????? //設置load函數 ??
  32. ????? this .setLoading?=? function ?(loadFunc){ ??
  33. ?????????? this .loading?=?loadFunc; ??
  34. ?????} ??
  35. ? ??
  36. ????? //設置send自帶的參數值,默認null ??
  37. ????? this .setContent?=? function ?(contents){ ??
  38. ???????? this .content?=?contents; ??
  39. ?????} ??
  40. ???? /*********get/set方法結束*******/ ??
  41. ? ??
  42. ???? /*********狀態顯示方法*********/ ??
  43. ????? //調用window.alert方法 ??
  44. ????? this .alert?=? function ?(msg){ ??
  45. ?????????window.alert(msg); ??
  46. ?????} ??
  47. ? ??
  48. ???? //調用window.status的方法 ??
  49. ????? this .status?=? function ?(msg){ ??
  50. ??????????window.status?=?msg; ??
  51. ?????} ??
  52. ???? /*********狀態顯示方法結束*********/ ??
  53. ? ??
  54. ???? /*************執行方法開始*****************/ ??
  55. ????? //創建HttpXMLRequest ??
  56. ????? this .createXMLRequest?=? function (){ ??
  57. ????? if (window.XMLHttpRequest){ ??
  58. ??????????? this ._httpReq?=? new ?XMLHttpRequest(); ??
  59. ??? ??
  60. ??????????? if ( this ._httpReq.overrideMimeType){ ??
  61. ??????????????? this ._httpReq.overrideMimeType( "text/xml" ); ??
  62. ???????????} ??
  63. ??????} else ? if (window.ActiveXObject){ ??
  64. ???????????? try { ??
  65. ????????????????? this ._httpReq?=? new ?ActiveXObject( "Msxml2.XMLHTTP" ); ??
  66. ????????????} catch (e){ ??
  67. ?????????????????? try { ??
  68. ??????????????????????? this ._httpReq?=? new ?ActiveXObject( "Microsoft.XMLHTTP" ); ??
  69. ??????????????????} catch (e){} ??
  70. ????????????}? ??
  71. ??????} ??
  72. ?} ??
  73. ? ??
  74. ????? //初始化ajax對象 ??
  75. ????? this .init?=? function (){ ??
  76. ?????????? this .createXMLRequest(); ??
  77. ?????} ??
  78. ? ??
  79. ????? //發送一個http請求 ??
  80. ????? this .send?=? function ?(){ ??
  81. ?????????? if ( this .resType.toLowerCase()== "post" ){ ??
  82. ??????????????????_httpReq.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" ); ??
  83. ??????????} ??
  84. ?????????? this ._httpReq.open( this .method, this .url, this .syn); ??
  85. ?????????? this ._httpReq.send( this .content); ??
  86. ?????} ??
  87. ? ??
  88. ???????? //取消一個http請求 ??
  89. ???????? this .abort?=? function ?(){ ??
  90. ??????????????? this ._httpReq.abort(); ??
  91. ????????} ??
  92. ? ??
  93. ?????? this .callbackState?=? function (){ ??
  94. ???????????? switch ( this ._httpReq.readyState){ ??
  95. ??????????????????? case ?0: ??
  96. ???????????????????????????? this .readystate?=?0; ??
  97. ???????????????????????????? break ; ??
  98. ??????????????????? case ?1: ??
  99. ???????????????????????????? this .readystate?=?1; ??
  100. ???????????????????????????? break ; ??
  101. ??????????????????? case ?2: ??
  102. ???????????????????????????? this .readystate?=?2; ??
  103. ???????????????????????????? break ; ??
  104. ??????????????????? case ?3: ??
  105. ???????????????????????????? this .readystate?=?3; ??
  106. ???????????????????????????? break ; ??
  107. ??????????????????? case ?4: ??
  108. ???????????????????????????? this .readystate?=?4; ??
  109. ???????????????????????????? switch ( this ._httpReq.status){ ??
  110. ??????????????????????????????????? case ?200: ??
  111. ???????????????????????????????????????????eval( this .callback); ??
  112. ??????????????????????????????????????????? break ; ??
  113. ??????????????????????????????????? case ?202: ??
  114. ??????????????????????????????????????????? this .status( "請求處理中,還沒處理完畢!" ); ??
  115. ??????????????????????????????????????????? break ; ??
  116. ??????????????????????????????????? case ?400: ??
  117. ??????????????????????????????????????????? this .status( "錯誤的請求!" ); ??
  118. ??????????????????????????????????????????? break ; ??
  119. ??????????????????????????????????? case ?404: ??
  120. ??????????????????????????????????????????? this .status( "請求資源未找到!" ); ??
  121. ??????????????????????????????????????????? break ; ??
  122. ??????????????????????????????????? case ?500: ??
  123. ??????????????????????????????????????????? this .status( "內部服務器錯誤,請聯系管理員!" ); ??
  124. ??????????????????????????????????????????? break ; ??
  125. ??????????????????????????????????? default : ??
  126. ??????????????????????????????????????????? this .status( "返回數據失敗," + this ._httpReq.status); ??
  127. ??????????????????????????????????????????? break ; ??
  128. ??????????????????????????????} ??
  129. ?????????????????????????????? break ; ??
  130. ??????????????????? default : ??
  131. ??????????????????????????? this .readystate?=?0; ??
  132. ??????????????????????????? break ; ??
  133. ?????????????} ??
  134. ?????} ??
  135. ??
  136. ????? this .onReadyStateChange?=? function ?(){ ??
  137. ???????????? var ?owner?=? this ; ??
  138. ???????????? this ._httpReq.onreadystatechange?=? function (){ ??
  139. ???????????????????owner.callbackState.call(owner); ??
  140. ????????????} ??
  141. ?????} ??
  142. ? /*************執行方法結束*****************/ ??
  143. }??


雖然跟網上有些ajax封裝類有些類似,但這個確實是我自己寫出來的,雖然寫得不是特別好,而且還有些功能還沒完善,不過這個js類的確可以用來在小項目使用一些ajax技術時非常方便。歡迎批評!!

自己寫的ajax封裝js類


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩在线免费视频观看 | 羞羞答答www网站进入 | 一区二区三区欧美在线观看 | 奇米影视在线播放 | 奇米激情 | 亚洲五月综合网色九月色 | 羞羞的视频在线 | 极品xxxx欧美一区二区 | 国产精品99在线观看 | 激情综合网俺也去 | 国产成人综合一区二区三区 | 久久精品国产免费看久久精品 | 日韩乱视频| 精品午夜久久网成年网 | 人人看人人搞 | 国产农村妇女毛片精品久久麻豆 | 亚洲天堂欧美在线 | 久久免费精品视频 | 精品久久久久一区二区国产 | 日本中文字幕在线播放 | 色吟av| 色诱成人免费观看视频 | 日本免费小视频 | 国产精品99999999| 国产精品视频免费观看 | 国内精品一区二区 | 久操网站 | 国内精品久久久久影院老司 | 日韩丝袜在线观看 | 国产精品美女久久久久久 | 亚洲高清中文字幕综合网 | 国产精品成人国产乱一区 | 嫩草影院在线入口 | 成人影视大全 | 亚洲天堂久久精品成人 | 国产精品国产a | 四虎永久免费地址ww 41.6 | 九九资源站| 不卡一二三区 | 波多野衣结在线精品二区 | 狠狠色老熟妇老熟女 |