zoukankan      html  css  js  c++  java
  • ajax手写代码实现

        <script type = "text/javascript">
        
    var xmlhttp = null;
        
    try
        {
            xmlhttp 
    = new ActiveXObject("Microsoft.XMLHTTP");
        }
        
    catch(e)
        {
            
    try
            {
                xmlhttp 
    = new XMLHttpRequest();
            }
            
    catch(e)
            {
                alert(
    "xmlhttp创建失败");
            }
        }
        
        
    function state_Change()
        {
            
    if(xmlhttp.readyState == 4)
            {
                
    if(xmlhttp.status == 200)
                {
                    
    var mes = xmlhttp.responseText;
                    document.getElementById(
    "t1").innerText=mes;
                }
            }
        }
        
        
    function GetMes()
        {
            
    //异步
            xmlhttp.open("POST" ,"Default.aspx",true);
            xmlhttp.onreadystatechange
    =state_Change;
            xmlhttp.send(
    null);

            
            
    //同步
            xmlhttp.open("POST","Default.aspx",false);
            xmlhttp.send(
    null);
            
    var mes = xmlhttp.responseText;
            document.getElementById(
    "t1").innerText=mes;
            
            setTimeout(GetMes,
    1000);
        }
        
        GetMes();
        
    </script>
  • 相关阅读:
    .Net Core使用Socket与树莓派进行通信
    c#中Socket网络通信的入门
    django 中 cookie与session 相关的知识
    怎么解决MySQL密码问题
    python 虚拟环境安装与卸载
    Linux 怎么清理缓存
    VMware 虚拟机黑屏问题
    如何在Ubuntu上给软件创建快捷方式
    Linux-Windows10双系统安装
    Tomcat开启JMX监控
  • 原文地址:https://www.cnblogs.com/bloodofhero/p/2046201.html
Copyright © 2011-2022 走看看