Ajax 强制刷新页面 By shawl.qiu

来源:互联网 发布:知乎论坛注册 编辑:程序博客网 时间:2024/05/06 01:25

Ajax 强制刷新页面 By shawl.qiu

说明:
没啥好说明的, 没了解 Ajax 之前, 很有一种神秘感, 了解后...好像觉着,有点过于简单了.
主要使用的还不就是无刷新的 get 与 post.

不过对于 Ajax , 令人头疼的是, 为什么会有好多种不同的浏览器.
而这些浏览器浏览网页时又有不少属于各自的属性方法.
但每个浏览器一推出新版本, 又会更好的兼容其他的浏览器, 但随着而来的是,
该新版本的浏览器又会有自己的新方法, 这简直就是一个做不完的梦.

好了, 啰嗦完了, 说重点.

本文只能实现 IE & Firefox 的强制刷新页面, 且只能刷新一个特定文件.
另, Firefox 不用设置啥就可强制刷新页面.
但对于 Opera, 我是没办法了, 去官网的 UserJs 查了一叠叠文章, 找不着可行方法...

shawl.qiu
2006-10-28
http://blog.csdn.net/btbtd/
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <!-- DW6 -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>shawl.qiu template</title>
  7. <script type="text/javascript">
  8. //<![CDATA[
  9. var XMLHTTP={
  10. //-----------------------------------begin request
  11. request:function(){
  12. try{
  13. return new XMLHttpRequest();
  14. } catch(e) {
  15. try{
  16. return new ActiveXObject('microsoft.xmlhttp');
  17. } catch(e){
  18. try{
  19. return new ActiveXObject("Msxml2.XMLHTTP");
  20. } catch(e){}
  21. }
  22. }
  23. },
  24. //-----------------------------------end request
  25. // begin text
  26. text:function(method, url, func){
  27. var request=XMLHTTP.request();
  28. request.open(method, url);
  29. request.onreadystatechange=function(){
  30. if(request.readyState==4&&request.status==200){
  31. if(func) func(request.responseText);
  32. else alert(request.responseText);
  33. }
  34. }
  35. request.send(null);
  36. },
  37. //-----------------------------------end text
  38. // begin reload
  39. reload:function(method, url){
  40. if(navigator.appName!='Netscape'){
  41. var request=XMLHTTP.request();
  42. request.open(method, url, true);
  43. try{ w.close(); } catch(e){}
  44. w=open('','');
  45. w.blur();
  46. w.opener.focus();
  47. request.onreadystatechange=function(){
  48. if(request.readyState==4&&request.status==200){
  49. w.close();
  50. location.reload(true);
  51. }
  52. }
  53. request.send(null);
  54. } else location.reload(true);
  55. }
  56. //-----------------------------------end reload
  57. } // shawl.qiu script
  58. //----------------------------------------end object XMLHTTP ----------------------------//
  59. onload=function(){ // 加载 sqEditor 按钮, 请以绝对地址加载.
  60. XMLHTTP.text('GET', 'sqEditor/sqEditorMarkupList.htm', fGetMarkupList);
  61. }
  62. function fGetMarkupList(obj){
  63. var o=document.getElementById('sqEditor');
  64. o.innerHTML=obj;
  65. } // shawl.qiu script
  66. //]]>
  67. </script>
  68. </head>
  69. <body>
  70. <div id="sqEditor"></div><!--显示 iframe 标签列表-->
  71. <br/><button onclick="XMLHTTP.reload('GET', 'sqEditor/sqEditorMarkupList.htm');">reload</button>
  72. </body>
  73. </html>


原创粉丝点击