45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:使用Ajax强制刷新页面的方法

使用Ajax强制刷新页面的方法

2016-09-03 11:50:57 来源:www.45fan.com 【

使用Ajax强制刷新页面的方法

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">
    • <html xmlns="http://www.w3.org/1999/xhtml">
      • <!-- DW6 -->
        • <head>
          • <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            • <title>shawl.qiu template</title>
              • <script type="text/javascript">
                • //<![CDATA[
                  • var XMLHTTP={
                    • //-----------------------------------begin request
                      • request:function(){
                        • try{
                          • return new XMLHttpRequest();
                            • } catch(e) {
                              • try{
                                • return new ActiveXObject('microsoft.xmlhttp');
                                  • } catch(e){
                                    • try{
                                      • return new ActiveXObject("Msxml2.XMLHTTP");
                                        • } catch(e){}
                                          • }
                                            • }
                                              • },
                                                • //-----------------------------------end request
                                                  • // begin text
                                                    • text:function(method, url, func){
                                                      • var request=XMLHTTP.request();
                                                        • request.open(method, url);
                                                          • request.onreadystatechange=function(){
                                                            • if(request.readyState==4&&request.status==200){
                                                              • if(func) func(request.responseText);
                                                                • else alert(request.responseText);
                                                                  • }
                                                                    • }
                                                                      • request.send(null);
                                                                        • },
                                                                          • //-----------------------------------end text
                                                                            • // begin reload
                                                                              • reload:function(method, url){
                                                                                • if(navigator.appName!='Netscape'){
                                                                                  • var request=XMLHTTP.request();
                                                                                    • request.open(method, url, true);
                                                                                      • try{ w.close(); } catch(e){}
                                                                                        • w=open('','');
                                                                                          • w.blur();
                                                                                            • w.opener.focus();
                                                                                              • request.onreadystatechange=function(){
                                                                                                • if(request.readyState==4&&request.status==200){
                                                                                                  • w.close();
                                                                                                    • location.reload(true);
                                                                                                      • }
                                                                                                        • }
                                                                                                          • request.send(null);
                                                                                                            • } else location.reload(true);
                                                                                                              • }
                                                                                                                • //-----------------------------------end reload
                                                                                                                  • } // shawl.qiu script
                                                                                                                    • //----------------------------------------end object XMLHTTP ----------------------------//
                                                                                                                      • onload=function(){ // 加载 sqEditor 按钮, 请以绝对地址加载.
                                                                                                                        • XMLHTTP.text('GET', 'sqEditor/sqEditorMarkupList.htm', fGetMarkupList);
                                                                                                                          • }
                                                                                                                            • function fGetMarkupList(obj){
                                                                                                                              • var o=document.getElementById('sqEditor');
                                                                                                                                • o.innerHTML=obj;
                                                                                                                                  • } // shawl.qiu script
                                                                                                                                    • //]]>
                                                                                                                                      • </script>
                                                                                                                                        • </head>
                                                                                                                                          • <body>
                                                                                                                                            • <div id="sqEditor"></div><!--显示 iframe 标签列表-->
                                                                                                                                              • <br/><button onclick="XMLHTTP.reload('GET', 'sqEditor/sqEditorMarkupList.htm');">reload</button>
                                                                                                                                                • </body>
                                                                                                                                                  • </html>
 

本文地址:http://www.45fan.com/a/question/71671.html
Tags: ajax 刷新 强制
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部