I basically have a form that you input chat messages into. It looks like chat roulette/omegle. You see yourself as YOU, and the 开发者_开发技巧other person as STRANGER. I need to be able to reload the messages without refreshing the page when submitted. This is at the bottom of the HTML page:
<script type="text/javascript">
$(document).ready(function(){
var refreshchat = function(){
$.get('ajax.php', function(data) {
$('#messages').html(data);
});
var msgs = document.getElementById('messages');
msgs.scrollTop = msgs.scrollHeight;
}
var getmsgs = self.setInterval(refreshchat,0);
$('#send').click(function(){
var msg = $('#msg').val();
$.post("ajax.php", { msg: msg, from: "You" },
function(data) {
$('#messages').html(data);
$('#msg').val('');
var msgs = document.getElementById('messages');
msgs.scrollTop = msgs.scrollHeight;
});
});
});
</script>
I saw this question/answer on stackoverflow, but am not sure how to make it work with this setup.
You need to create the send button. Edited: getmsgs is automatically called. Other than the button, the only thing I can think of is the ajax.php file. Is that created?
<input type="button" id="send">
精彩评论