2016-10-21 6 views
-1

그래서 chatbox 사이트 php 및 jquery 함께 만들었지 만 jquery 다른 두 가지 버전의 새 페이지 중 일부를 사용하여 서로 충돌을 추가했습니다 (나는 다른 페이지에 동시에 연결 두 JQuery와 버전을했다하더라도) 그래서 내가 감가 상각 모르는에 대한 이상 코드를 변환하는 데 도움이 필요하고 무엇을하지 여기 나의 JQuery와 1.3 코드jquery 2.2.2 내 jquery 1.3 코드를 변환하는 데 도움이 필요

// jQuery Document 
    $(document).ready(function() { 
     //If user submits the form 
     $("#submitmsg").click(function() { 
      var clientmsg = $("#usermsg").val(); 
      $.post("/chatPost/defaultchatpost.php", { 
       text: clientmsg 
      }); 
      $("#usermsg").attr("value", ""); 
      return false; 
     }); 
     //Load the file containing the chat log 
     function loadLog() { 
      var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20; 
      $.ajax({ 
       url: "/chatLogs/defaultchatlog.html", 
       cache: false, 
       success: function(html) { 
        $("#chatbox").html(html); //Insert chat log into the #chatbox div 
        var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20; 
        if (newscrollHeight > oldscrollHeight) { 
         $("#chatbox").animate({ 
          scrollTop: newscrollHeight 
         }, 'normal'); //Autoscroll to bottom of div 
        } 
       }, 
      }); 
     } 
     setInterval(loadLog, 500); //Reload file every 2.5 seconds 
     //If user wants to end session 
     $("#exit").click(function() { 
      var exit = confirm("Are you sure you want to end the session?"); 
      if (exit == true) { 
       window.location = 'defaultchat.php?logout=true'; 
      } 
     }); 
    }); 
입니다

누군가 나를 크게 도와 주시면 감사하겠습니다. 오랫동안 이것을 알아 내려고 노력했습니다.

+3

는 지금까지의 내가 볼 수있는 그 jQuery를에 일을해야 main.html, 당신은 오류가 점점 도움이되기를 바랍니다? 그렇다면 무엇입니까? –

+0

jquery 2.2.2로 아무 것도하지 않는다는 것을 모릅니다. –

+0

많은 기능이없는 문서를 확인하십시오. – scrappedcola

답변

0

ajax html을 사용하여 기본 인터페이스에서 /chatLogs/defaultchatlog.html을 호출 할 수 있습니다. 이 경우 html 파일이라는 다른 아약스에서도 defaultchatlog.html에 jquery를 추가 할 필요가 없습니다. 모든 함수는 ajax html을 통해 호출되는 부분 HTML 파일이 아닌 기본 UI에 있어야합니다. 예를 들어 : main.html 및 defaultchatlog.html ... 나는이

은 어디에도 없습니다

<html> 
    <head> 
     <scrpt src="jquery.js"></script> 
    </head> 
    <body> 
     <div id="chatWindows"></div> 
    </body> 
    <script> 
     $(document).ready(function(){ 
      $.ajax({ 
      url: "chatlog.html", 
      cache: false, 
      success: function(html) { 
       $("#chatWindows").html(html); //Insert chat log into the #chatbox div 
      }, 
     }); 
     }); 
     function clearLogs(){ 
      $("#logs").empty(); 
     } 
    </script> 
</html> 

chatlog.html 

<div> 
    <ul id="logs"> 
     <li>Hi</li> 
    </ul> 
    <button onclick="clearLogs();">Clear</button> 
</div>