隨筆 - 1, 文章 - 0, 評論 - 0, 引用 - 0
          數據加載中……

          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 閱讀(110) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 太仓市| 嫩江县| 石台县| 汉阴县| 申扎县| 濮阳市| 思茅市| 鄂托克旗| 石景山区| 大埔区| 长宁区| 平邑县| 哈巴河县| 娄烦县| 锡林浩特市| 青河县| 花莲县| 鄂尔多斯市| 惠州市| 射洪县| 洛宁县| 铁岭县| 图们市| 前郭尔| 珠海市| 郁南县| 于都县| 天气| 江陵县| 察哈| 金寨县| 民乐县| 宜丰县| 壤塘县| 石楼县| 隆回县| 昌平区| 公主岭市| 商河县| 临武县| 金阳县|