zoukankan      html  css  js  c++  java
  • Ajax(Asychronous JavaScript and XML)笔记

    1 Ajax简介

    1 ajax概念

    2 什么是同步?什么是异步?

    3 ajax原理

    2 JavaScript原生的ajax

     1 ajax.html代码

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    <script type="text/javascript">
    
        function fn1(){
            //1、创建ajax引擎对象 ---- 所有的操作都是通过引擎对象
            var xmlHttp = new XMLHttpRequest();
            //2、绑定监听 ---- 监听服务器是否已经返回相应数据
            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState==4&&xmlHttp.status==200){
                    //5、接受相应数据
                    var res = xmlHttp.responseText;
                    document.getElementById("span1").innerHTML = res;
                }
            }
            //3、绑定地址
            xmlHttp.open("GET","/WEB22/ajaxServlet?name=lisi",true);
            //4、发送请求
            xmlHttp.send();
            
        }
        function fn2(){
            //1、创建ajax引擎对象 ---- 所有的操作都是通过引擎对象
            var xmlHttp = new XMLHttpRequest();
            //2、绑定监听 ---- 监听服务器是否已经返回相应数据
            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState==4&&xmlHttp.status==200){
                    //5、接受相应数据
                    var res = xmlHttp.responseText;
                    document.getElementById("span2").innerHTML = res;
                }
            }
            //3、绑定地址
            xmlHttp.open("POST","/WEB22/ajaxServlet",false);
            //4、发送请求
            xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xmlHttp.send("name=wangwu");
            
        }
    
        
    </script>
    
    </head>
    <body>
        <input type="button" value="异步访问服务器端" onclick="fn1()"><span id="span1"></span>
        <br>
        <input type="button" value="同步访问服务器端" onclick="fn2()"><span id="span2"></span>
        <br>
        <input type="button" value="测试按钮" onclick="alert()">
    </body>
    </html>

    2 AjaxServlet代码

    package www.test.ajax01;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class AjaxServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            
            //response.getWriter().write("zhangsan");
            
            /*try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
            
            String parameter = request.getParameter("name");
            
            response.getWriter().write(Math.random()+parameter);
            
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
        }
    }

    3 注意事项

    4 ajax图解

  • 相关阅读:
    faster with MyISAM tables than with InnoDB or NDB tables
    w-BIG TABLE 1-toSMALLtable @-toMEMORY
    Indexing and Hashing
    MEMORY Storage Engine MEMORY Tables TEMPORARY TABLE max_heap_table_size
    controlling the variance of request response times and not just worrying about maximizing queries per second
    Variance
    Population Mean
    12.162s 1805.867s
    situations where MyISAM will be faster than InnoDB
    1920.154s 0.309s 30817
  • 原文地址:https://www.cnblogs.com/jepson6669/p/8359026.html
Copyright © 2011-2022 走看看