Bigg Posted April 16, 2007 Share Posted April 16, 2007 Hey I'm trying to make a chat using php and AJAX that doesn't use a database and instead uses a form of server push to get messages from clients. Here's what I got so far. <html> <body> <script type="text/javascript"> function Makesobject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('g').innerHTML = 'Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.'; } } function ajaxFunction() { var xmlHttp = Makesobject() xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById("echoed").value=unescape(xmlHttp.responseText); } } //alert ("1.php?message="+document.getElementById("2").value+"&username="+document.getElementById("ur").value) xmlHttp.open("GET","1.php?message~"+document.getElementById("2").value+"&username~ : "+document.getElementById("ur").value,true); xmlHttp.send(null); } </script> <form name="myForm"> Name: <input type="text" name="message" id="2" > <P id="g"></P> Message: <input type="text" name="username" id="ur" > <P> <textarea name= "echoed" cols="35" rows="8" id="ec" col="40"> </textarea> <input type="button" onClick="ajaxFunction()" value="Submit"> </form> </body> </html> And the 1.php is <?php //echo $_SERVER['QUERY_STRING']; $outerarray = explode("&", $_SERVER['QUERY_STRING']); $that = explode ("~",$outerarray[0]); echo $that[1]; $that = explode ("~",$outerarray[1]); echo $that[1]; ?> Does anybody have any ideas for the rest as to the server push or like timeout to the server for messages? I'm still a little new to php so please explain your code step by step. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.