Ajax动态函数调用

时间:2016-06-01 01:10:57

标签: javascript jquery ajax jsp

我想动态调用查询。除了打印声明,一切似乎都有效它不会在页面上打印语句。 我有两个文件第一个detail.JSP和chat.JSP

   <%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
   <%@ page import = "models.*"%>
 <%@ page import= "java.util.*"%>
 <html>
 <head>
 <title> chat system  </title>
 <script>

 function ajax(){
     var req = new XMLHttpRequest();
 req.readystatechange = function(){
        if(req.readyState == 4 && req.status==200){

            document.getElementById('chat').innerHTML = req.responseText;



        }


    }

    req.open('GET','/member/chat.jsp',true);
    req.send();
}


setInterval(function(){ajax()},1000);

  

 <div id="container">

  <%

MemberDao dao = new MemberDao();

System.out.println("11111");

String tid=null;

tid = request.getParameter("tid");
System.out.println("tid:"+tid);
if(tid==null){
    System.out.println("tid is null");
     tid = (String)session.getAttribute("tid");

}else{
    System.out.println("tid is  not null");
    tid = request.getParameter("tid");
}







String myid =(String) session.getAttribute("idA");
MemberDto dto = dao.readOne(tid);
MemberDto idAdto = dao.readOne(myid);
WritingDao wdao = new WritingDao();
List<WritingDto> all = wdao.readMyMessage(myid);
System.out.println("==================="+all.size()+"conn::");
System.out.println("2222");
%>


 <h2>Member information</h2>
 <% System.out.println("333333");%>
 Send text <br/>
 ID:<%=dto.getId()%>  password:<%=dto.getPass()%><br/>
 <br/>
 <form action="/member/detailhandler.jsp"  class="login-form">
 <input type="text" name="tid" value =<%=tid%> ><br>
 <input type="text" id="text" name="text_name" style="height:200px;"            style="width: 200px;" 
  placeholder="your writing here" /><br/>
 <button>submit</button>
 </form>

 <% System.out.println("444444");%>
 <br/>
 The messages <br/><br/>

 <% 

 %> <div id="chat_box">


<div id ="chat"></div>

       
<a href="/pop/closepage.jsp">CLOSE</a>
</div>
</body>
</html>

我对AJAX的理解是这个ajax()函数应该调用

               <div id ="chat"></div>

但此功能在

之后调用
               <% System.out.println("5555555");%>

所以这是我的第一个问题:为什么ajax()函数没有调用

               <div id ="chat"></div>

这是我的聊天.JSP

 <%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
 <%@ page import = "models.*"%>
 <%@ page import= "java.util.*"%>

  <% 
  String myid2 =(String) session.getAttribute("idA");
  System.out.println("ida:::::::::"+myid2);
  WritingDao wdao2 = new WritingDao();
  List<WritingDto> all2 = wdao2.readMyMessage(myid2);
  for(WritingDto t : all2) { %>
  <%System.out.println("getNum:::"+t.getNum()+":: id ::"+t.getContext()); %>

  FROM::
  <span style="color:green;"><%=t.getSendid() %>::  </span>
  <span style="color:brown;"><%=t.getContext() %>   </span> <br/>
  <% System.out.println("hello");%>

 <% }
 %>

我可以看到Ajax()函数正在查看Sysout.out.print的事情 但问题是

        FROM::
     <span style="color:green;"><%=t.getSendid() %>::  </span>
     <span style="color:brown;"><%=t.getContext() %>   </span> <br/>
     <% System.out.println("hello");%>

    <% }
    %>

此部分未在屏幕上显示。这是我提出的第二个问题。

0 个答案:

没有答案