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

          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 on 2007-09-01 11:45 chenbo 閱讀(109) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 新乡市| 潢川县| 江川县| 临江市| 溧阳市| 穆棱市| 双牌县| 礼泉县| 尉犁县| 南投县| 灯塔市| 宁津县| 乐陵市| 新密市| 清流县| 绍兴市| 东阳市| 巴彦县| 马公市| 大邑县| 淮阳县| 常熟市| 阿合奇县| 黎平县| 顺昌县| 秀山| 汉川市| 张家港市| 客服| 定安县| 新营市| 新建县| 昭平县| 九台市| 庆云县| 惠州市| 榆林市| 西乡县| 延长县| 保山市| 泸水县|