rahuul Posted July 16, 2009 Share Posted July 16, 2009 hello friends, I am tying to make a chat application using PHP (Ajax). I am new to ajax pls help me with my code <html> <head> <script type="text/javascript"> function ajaxFunction() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } xmlhttp.onreadystatechange=function() { if(xmlhttp.readyState==4) { document.myForm.displaymsg.value=xmlhttp.responseText; } } xmlhttp.open("POST","display.php",true); xmlhttp.send(null); } </script> </head> <body> <fieldset> <center> <div style="align: left; border:1px solid blue;margin-top:10;margin-bottom:10;px;padding:10px;height=4;width:200px"> <?php session_start(); require("db.php"); echo "WELCOME : User"; ?> </div> <form action="window.php" method="post" onsubmit="ajaxFunction();" name="myForm"> <textarea align="left" style="border:1px solid blue;margin-top:5;margin-bottom:10;px;padding:10px" rows="20" cols="50" readonly="readonly" name="displaymsg"> </textarea> <?php require("db.php"); session_start(); if($_SESSION['logged']==1){ if(isset($_POST['send'])){ $msg=$_POST['msg']; $uid=$_SESSION['uid']; $sql="INSERT INTO message VALUES('$uid','','$msg')"; $result=mysql_query($sql) or die(mysql_error()); } } ?> <fieldset> <textarea name="msg" rows="5" cols="30"></textarea><br> <input type="submit" name="send" value="send"> </form> </fieldset> </center> </body> </html> pls help me where should i call ajaxFunction() in the script. at present when i submit new text the text displayed in textarea for less then a second and then goes blank.... pls help...... thanks Link to comment https://forums.phpfreaks.com/topic/166220-chat-application-in-phpajax-pls-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.