zoukankan      html  css  js  c++  java
  • 一个简单的AJAX实现(HELLO AJAX)

    客户端部分:

    <html>

    <head>
        
    <meta http-equiv="Content-Type" content="text/html"/>
        
    <script language="javascript">
            
    var ajax;
            
    function createAjax()
            {
                
    if(window.ActiveXObject)
                {
                    
    try
                    {
                        
    return new ActiveXObject("Msxm12.XMLHTTP");
                    }
                    
    catch(e)
                    {
                        
    try
                        {
                            
    return new
                                    ActiveXObject(
    "Microsoft.XMLHTTP");
                        }
                        
    catch(e2)
                        {
                            
    return null;
                        }
                    }
                }
                
    else if(window.XMLHttpRequest)
                {
                    
    return new XMLHttpRequest();
                }
                
    else
                {
                    
    return null;
                }
            }
            
    function onRcvData()
            {
                
    if(ajax.readyState==4)
                {
                    
    if(ajax.status==200)
                    {
                        
    var content=document.getElementById('content');
                        content.innerHTML
    =ajax.responseText;
                    }
                    
    else
                    {
                        alert(
    "error");
                    }
                }
            }
            
    function ajaxSendRequest(uri)
            {
                ajax
    =createAjax();
                
    if(!ajax)
                {
                    alert(
    "no");
                    
    return 0;
                }
                
                ajax.onreadystatechange
    =onRcvData;
                ajax.open(
    "GET",uri,true);
                ajax.send(
    "");
            }
        
    </script>
    <title>Hello AJAX</title>

    </head>

    <body>
        
    <div id="content"></div>
        
    <br>
        
    <input type="button" value="Hello" 
            onclick
    ="ajaxSendRequest('http://localhost:8080/test/hello.jsp')">
    </body>

    </html>

    服务器端部分(hello.jsp)

    <html>
        
    <head>
            
    <title>hellp</title>
        
    </head>
        
    <body>
           
    <%
              out.println(
    "HELLO AJAX");
           
    %>
        
    </body>
    </html>
  • 相关阅读:
    21.Android之SQLite数据库学习
    20.(转)Android的样式(Style)和主题(Theme)
    19.Android之文件存储方法学习
    18.Android之SharedPreferences数据存储学习
    17.(转) Android之四大基本组件介绍与生命周期
    16.(转) Android之Support v4、v7、v13的区别和应用场景
    15.Android中LinearLayout布局一些小记录
    14.Android之Layout布局学习
    13. (转) Android一些布局属性详解
    12.Android之Tabhost组件学习
  • 原文地址:https://www.cnblogs.com/xpxu/p/1683844.html
Copyright © 2011-2022 走看看