zoukankan      html  css  js  c++  java
  • AJAx无刷新

    var xmlHttp=false;//创建一个布尔型变量,用来检测是否为合法的IE实例
    try{                //检测是否使用的是IE
        xmlHttp=new ActionXObject('Msxml2.xmlHttp');//如果JS版本大于5
    }catch(e){            //如果不是,则使用老版本的ActionX对象
        try{            
            xmlHttp=new ActionXObject("Microslft.xmlHttp");//如果使用的是IE 浏览器
        }catch(e2){}
    }
    //如果使用的是非IE浏览器,则创建一个该对象的js实例
    if(!xmlHttp && typeof xmlHttpRequest!="undefined"){
        try{
            xmlHttp=new xmlHttpRequest();
        }catch(e3){
            xmlHttp=false;
        }
    }

    timer=window.setInterval("ShowTime()",1000);//每隔一秒调用一次ShowTime函数
    //定义showTime函数通过xmlhttprequest对象读取Showtime.php文件中的数据
    function ShowTime(){
        xmlHttp.open("post","showtime.php",true);//以Post方法发送一个新请求
        xmlHttp.onreadystatechange=function(){
            if(xmlhttp.readyState==4){            //如果服务器响应发出请求,则执行以下操作
                tet=xmlhttp.responseText;        //获取返回的响应信息
                //获取的信息赋予div标记
                document.getElementById("show_time").innerHTML=tet;
            }
        }
        xmlhttp.send(null); //发送请求
    }


    timer=window.setInterval("sparetime()",1000);//每隔一秒调用一次sparetime函数
    //定义sparetime函数通过xmlhttprequest对象读取sparetime.php文件中的数据
    function sparetime(){
        xmlHttp.open("post","sparetime.php",true);//以Post方法发送一个新请求
        xmlHttp.onreadystatechange=function(){
            if(xmlhttp.readyState==4){            //如果服务器响应发出请求,则执行以下操作
                tet=xmlhttp.responseText;        //获取返回的响应信息
                //获取的信息赋予div标记
                document.getElementById("sparetime").innerHTML=tet;//当剩余时间为00:00时
                if(tet=="00:00"){                //提交form1表单中的数据
                    form1.submit();            
                }
            }
        }
        xmlhttp.send(null); //发送请求
    }

  • 相关阅读:
    百度笔试题:找最小的不重复数
    [置顶] 【收藏】实用软件
    指针数组与数组指针
    根据新浪天气API获取各地天气状况(Java实现)
    项目经历——EasyUI的检索和更新操作
    利用MyEclipse配置S2SH三大框架篇-Spring配置
    Intellij IDEA 最头大的问题,如何自定义注释模板?
    Spring Cloud Gateway VS Zuul 比较,怎么选择?
    Spring Boot 注册 Servlet 的三种方法,真是太有用了!
    Spring Cloud Eureka 常用配置详解,建议收藏!
  • 原文地址:https://www.cnblogs.com/lemon66/p/4088567.html
Copyright © 2011-2022 走看看