隨筆 - 1, 文章 - 0, 評論 - 0, 引用 - 0
          數(shù)據(jù)加載中……

          2007年9月1日

          simple ajax practice

          <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
          <%
          String path = request.getContextPath();
          String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
          %>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
            <head>
              <base href="<%=basePath%>">
              <%
               
                 String contextpath = request.getContextPath();
                  System.out.println(contextpath);
              %>
              <title>My JSP 'test.jsp' starting page</title>
              <script>
                 var ajax;
                 function insertCell(){
                     var url = "<%=contextpath%>/get"
                 
                     if(window.XMLHttpRequest){
                        ajax = new XMLHttpRequest();
                        if(ajax.overrideMimeType){
                           ajax.overrideMimeType('text/xml');
                        }
                     }else if(window.ActiveXObject){
                        ajax = new ActiveXObject("Microsoft.XMLHTTP");
                     }
                     ajax.open("GET",url,true);
                    
                     ajax.onreadystatechange = processRequest;
                     ajax.send();
                 }
                 function processRequest(){
                    if(ajax.readyState == 4){
                           //alert("1111"+ajax.status);
                    
                        //alert(ajax.status);
                        if(ajax.status == 200){
                           var response = ajax.responseText;
                           insertReportList(response);
                        }
                    }
                 }
            function insertReportList(str) {
              var tr = "";
              var td = "";
              tr = mytable.insertRow(mytable.rows.length);
              td = tr.insertCell(0);
              td.innerHTML = str;
            
          }
             </script>
            </head>
           
            <body>
              This is my JSP page. <br>
              <input type = button name = "test" value = "click" onclick = insertCell()>
              <table id = mytable>
                <tr><td>Description</td></tr>
              </table>
            </body>
          </html>

          posted @ 2007-09-01 11:45 chenbo 閱讀(109) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 辛集市| 扶风县| 阜平县| 工布江达县| 定南县| 涿州市| 普洱| 修水县| 北辰区| 星子县| 县级市| 饶阳县| 浦江县| 万盛区| 北流市| 息烽县| 安龙县| 申扎县| 乐东| 旬阳县| 岑巩县| 犍为县| 瑞昌市| 马鞍山市| 沽源县| 格尔木市| 金坛市| 泾川县| 清新县| 吉安县| 嘉黎县| 盘锦市| 北碚区| 宁夏| 邵阳市| 含山县| 浙江省| 兴业县| 攀枝花市| 天津市| 额尔古纳市|