Reputation: 1
So i have a chatroom site built with php and jquery but it is using 2 different versions of jquery and some of the new pages i have added conflict with each other (even though i had both jquery versions linked at the same time on the other pages) so i need help converting the code over for i do not know what is depreciated and what is not here is my jquery 1.3 code
// 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';
}
});
});
can someone please help me it would be greatly appreciated i have tried to figure this out for a long time
Upvotes: -1
Views: 47
Reputation: 119
It seems your trying to call /chatLogs/defaultchatlog.html from your main interface using ajax html. In that case you do not have to add jquery in your defaultchatlog.html, even in other ajax called html files. All functions must be in the main UI not in the partial html files which are called via ajax html. For example: main.html and defaultchatlog.html... I hope this helps
main.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>
Upvotes: 0