scarhand Posted October 5, 2007 Share Posted October 5, 2007 Hi, I am really frustrated with this, I am new to ajax so maybe Im not seeing something here that one of you gurus might. The problem is not saving the data to my mysql database, that works fine, the problem is that it is not properly updating/showing the data in my DIV. Here is the coding for my files: shoutbox.js: function ajaxFunction(){ var ajaxRequest; try { ajaxRequest = new XMLHttpRequest(); } catch (e) { try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // browser does not support alert("Browser does not support Shoutbox requests."); return false; } } } return ajaxRequest; } function showData() { htmlRequest = ajaxFunction(); if (htmlRequest==null) { alert ("Browser does not support HTTP requests."); return; } htmlRequest.onreadystatechange = function() { if(htmlRequest.readyState == 4) { document.getElementById("shoutarea").innerHTML = htmlRequest.responseText; } } htmlRequest.open("GET", "sb_get.php", true); htmlRequest.send(null); } showData(); setInterval("showData()", 1000); shoutbox.php: <?php define('IN_PHPBB', true); $phpbb_root_path = './'; include($phpbb_root_path . 'extension.inc'); include($phpbb_root_path . 'common.'.$phpEx); $userdata = session_pagestart($user_ip, PAGE_INDEX); init_userprefs($userdata); ?> <html> <head> <title>Shoutbox</title> <script language="JavaScript" type="text/javascript" src="shoutbox.js"></script> </head> <body> <div id="shoutarea"></div> <form name="shoutform" method="POST" onsubmit="saveData(); return false;"> Message: <input type="text" name="message" /> <br /> <input type="submit" name="submit" value="Shout it" /> </form> </body> </html> sb_get.php: <?php include("sb_connect.php"); $getshout_query = "SELECT id, name, message, DATE_FORMAT(time, '%h:%i') as time FROM shoutbox ORDER BY id DESC LIMIT 25"; $getshout_result = mysql_query($getshout_query) or die(mysql_error()); while($row = mysql_fetch_array($getshout_result)) { $name = $row['name']; $time = $row['time']; $message = $row['message']; echo "<div>($time) $name: $message</div>"; } ?> Now I'm not really sure about how the header information works in sb_get.php....maybe thats the issue. Thank you for any help you provide. Quote Link to comment https://forums.phpfreaks.com/topic/71944-solved-help-with-really-simple-phpmysqlajax-shoutbox/ Share on other sites More sharing options...
RichardRotterdam Posted October 5, 2007 Share Posted October 5, 2007 i am not gonna try your code on my server instead i'm going to give you some tips to find the error. 1. check if your sb_get.php gives any output if you put it in your browser url directly it should give some html output and also check out the browser source 2. see if something happens with your showData(); js function if you place it on a onclick example <button onclick="showData();">show data function call</button> 3. if the onclick thing worked try putting setInterval("showData()", 1000); on the onload option <body onload="setInterval("showData()", 1000);"> this should be enough to solve your problem Quote Link to comment https://forums.phpfreaks.com/topic/71944-solved-help-with-really-simple-phpmysqlajax-shoutbox/#findComment-362380 Share on other sites More sharing options...
scarhand Posted October 6, 2007 Author Share Posted October 6, 2007 ahh i solved it on my own yesterday thanks though kat Quote Link to comment https://forums.phpfreaks.com/topic/71944-solved-help-with-really-simple-phpmysqlajax-shoutbox/#findComment-363082 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.