javascript - How to post UL appended messages to php -
i have site in appended messages submitted unordered list act messenger/chat system. problem, site active, messages appended dont appear on other users screens. meaning messages submit, local screen. need if message submitted, appears see.
now i'm pretty sure because messages arent powered php, theyre not being uploaded server. theyre staying local. how upload these messages server? javascript? able working?
my html is:
<ul id="messagebox" ></ul> <div> <input type="text" id="typetextbox" maxlength="100" autocomplete="off" /> <button type="submit" id="submit" onblur="submit"> </button> </div>
and javascript is:
$(document).ready(function(){ $('#typetextbox').keypress(function (e){ if(e.keycode == 13 ) $('#submit').click(); }); $('#submit').click(function(){ var message = $('#typetextbox').val(); if (message.replace(/ /g, '')){ var positions = makenewposition(); var el = $('<li>'+message+'</li>'); el.attr('gridpos', positions[0].tostring()+"x"+positions[1].tostring()) el.css('left', positions[1] * window.li_width); el.css('top', positions[0] * window.li_height); el.fadein(200); $('#messagebox').append(el); } }); });
if has ideas how working it'd appreciated.
also if i'm not totally clear, let me know!
you need server manage state of sent , received messages between each of clients. suggest doing research on websockets.
i use http://pusher.com/ publish/subscribe event manager known subscribers receive messages published particular channel (aka room or topic). provide several examples, including real-time chat demo.
another option http://socket.io/ has demo chat application , source code.
it's worth time use 1 of these real-time messaging systems if you're creating chat application.
Comments
Post a Comment