必承其重 | 欲带皇冠 2016-06-01 01:10 采纳率: 0%
浏览 32

Ajax动态函数调用

I want to call query dynamically. everything seemed working except printing statement. It does not print the statement on the page. I have two files first detail.JSP and 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>

The way I understood about AJAX is this ajax() function should call in

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

but this function called after

               <% System.out.println("5555555");%>

So this is my first question: why ajax() function did not call in

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

And this is my chat.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");%>

 <% }
 %>

I can see the Ajax() function is working to see the Sysout.out.print things but the problem is

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

    <% }
    %>

This part does not shows on the screen.This is the second question i ask.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。