2015-01-07 2 views
0

- JSP로 새로 생겼습니다. mySQL 데이터베이스에서 데이터를 검색하는 데 XMLHTTP를 사용하고 있지만 데이터를 업데이트 한 후에는 업데이트 된 데이터가 아닌 이전 데이터 만 표시합니다. 솔루션입니다. 라디오 버튼이 있습니다.XMLHTTP로 새로 고침 문제

<td class="inputs_new"> <div id = "UT2"> 

         <% 
         for (int i = 0; i < thinClientName.size(); i++) { 

         %> 
         <input type = "radio" class = "my-button2" onclick="get()" id = "thinClnt_rad" name ="thinClnt_rad" value = "<%=thinClientName.get(i)%>" > 
         <% 
         out.println(thinClientName.get(i)); 
         } 
         %> 



    </div> 

    //Get function 

     function get() 
     { 

     var save_thin = ""; 
    for (var i = 0; i < document.getElementsByName('thinClnt_rad').length; i++) 
     { 
      if (document.getElementsByName('thinClnt_rad')[i].checked) 
      { 
       save_thin = document.getElementsByName('thinClnt_rad')[i].value; 
      } 
     } 

      var xmlhttp= GetXmlHttpObject1(); 
      xmlhttp.onreadystatechange=function() 
       { 
       if (xmlhttp.readyState==4 && xmlhttp.status==200) 
       { 

       var respTest = xmlhttp.responseText; 
       var res = respTest.split(";"); 

       document.getElementById("thinClientName").value=res[0]; 
       document.getElementById("Model").value=res[1]; 
       document.getElementById("SrNo").value=res[2]; 
       document.getElementById("ProductID").value=res[3]; 
       document.getElementById("sprNo").value=res[4]; 
       document.getElementById("MacAdd").value=res[5]; 
       document.getElementById("IPAdd").value=res[6]; 
       document.getElementById("Script").value=res[7]; 
      document.getElementById("VedName").value =res[10] ; 
       document.getElementById("playtime").value = res[11] ; 

       var sid_2=res[8]; 

    var options= document.getElementById('lstLocation').options; 

    for (var i= 0; i <options.length ; i++) 
     { 
      if (options[i].text==sid_2) { 

       document.getElementById("lstLocation").selectedIndex = i; 
      } 
     } 


     var sid_21=res[9]; 

    var options= document.getElementById('state').options; 

    for (var i= 0; i <options.length ; i++) 
     { 
      if (options[i].text==sid_21) { 

       document.getElementById("state").selectedIndex = i; 
      } 
     } 


      } 

       } 


      xmlhttp.open("GET","GetData.jsp?q="+save_thin,true); 
      xmlhttp.send(null); 

     } 
    function GetXmlHttpObject1() 
    { 
     if (window.XMLHttpRequest) 
     { 
      return new XMLHttpRequest(); 
     } 
     if (window.ActiveXObject) 
     { 
      return new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
    return null; 
    } 

    // and getData.jsp 
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
     pageEncoding="ISO-8859-1"%> 
     <%@ page import = "java.io.*,java.sql.*" %> 

     <%@page import= "jdbc.DBConnection" %> 


    <% 


      String str=request.getParameter("q"); 


      try 
      { 
       DBConnection con_obj = new DBConnection(); 
       Connection con = con_obj.getConnection(); 
       Statement stmtThinInfo = null; 
       Statement stmt_play = null; 
       ResultSet rsThinInfo = null; 
       ResultSet rs_play = null; 
       String q =request.getParameter("q"); 
       stmtThinInfo = con.createStatement(); 

      rsThinInfo = stmtThinInfo.executeQuery("select * from thinclient_tbl where name = '"+q+"'"); 
      while (rsThinInfo.next()) 
      { 


       stmt_play = con.createStatement(); 
       rs_play = stmt_play 
         .executeQuery("Select * from thin_videotable where Thin_Client = '" 
         + q + "'"); 
       String outPut; 
       if (rs_play.next()) { 

       outPut = rsThinInfo.getString("name") + ";" + rsThinInfo.getString("modell") + ";" + rsThinInfo.getString("serialnumber") + ";" + rsThinInfo.getString("product_id") + ";" + rsThinInfo.getString("spare_nr")+ ";" + rsThinInfo.getString("MAC-Adresse") + ";" + rsThinInfo.getString("IP-Adresse") + ";" + rsThinInfo.getString("script") + ";" + rsThinInfo.getString("location")+ ";" + rsThinInfo.getString("state") + ";" + rs_play.getString("VideoName") + ";" + rs_play.getString("Video_time"); 
       response.getWriter().write(outPut); 
    System.out.println(outPut); 
       } 
       else 
       { 
        outPut = rsThinInfo.getString("name") + ";" + rsThinInfo.getString("modell") + ";" + rsThinInfo.getString("serialnumber") + ";" + rsThinInfo.getString("product_id") + ";" + rsThinInfo.getString("spare_nr")+ ";" + rsThinInfo.getString("MAC-Adresse") + ";" + rsThinInfo.getString("IP-Adresse") + ";" + rsThinInfo.getString("script") + ";" + rsThinInfo.getString("location")+ ";" + rsThinInfo.getString("state") + ";" ; 
        response.getWriter().write(outPut); 
        System.out.println(outPut); 
       } 

      } 
      } 
      catch(Exception e) 
      { 

       e.printStackTrace(); 
      } 



    %> 

제안 사항이 있으면 알려주십시오.

+0

사람들이 당신을 도울 수 있도록 몇 가지 코드를 공유해야합니다. – Relequestual

+0

라디오 버튼이 있습니다. –

+0

코드를 포함하려면 질문을 편집해야합니다. 사람들이 당신을 도울 수 있도록 귀하의 질문에 충분한 정보가 없습니다. – Relequestual

답변

0

IE에서 사용해 보시겠습니까? IE는 공격적인 캐싱으로 유명하며 전체 페이지를 새로 고칠 때까지 동일한 AJAX 쿼리에 대해 동일한 결과를 반환합니다.

쿼리 문자열에 임의 식별자를 포함 할 수 있습니다. 시험해보기 :

xmlhttp.open("GET","GetData.jsp?q="+save_thin+"&rand="+Math.random(),true); 
+0

예. IE에서 시도 중입니다. 모질라에서 정상적으로 실행됩니다. –

+0

고유 한 요청을 생성하는 문자열에 임의의 식별자 (또는 날짜 + 시간)를 추가해보십시오. 때마다. jQuery와 함께 AJAX를 사용하는 경우 캐싱을 비활성화 할 수도 있습니다. 그것이 작동하는 경우 답변을 질문 틱하십시오 :) – Playmaker