almightyegg Posted September 10, 2007 Share Posted September 10, 2007 but when it came to testing it....I got nothing I am trying to make a chatroom using 3 pages... index.php - where the data is displayed request.php - whereI select the data from database I need ajax.js - which is meant to access request.php every 10 milliseconds, and pull the stuff through into index.php at the moment I have an incling that it might be retrieving the variable in the link request.php?room=$room (room being which chat room it is in index.php?room=$room) index.php <? include 'db.php'; // Connect to DB $email = $_COOKIE['email']; $password = $_COOKIE['password']; if((!$email) || (!$password)){ echo "There was an error in your details.<br />"; include 'http://www.lordoftheabyss.com/index.php'; exit(); }else{ $sql = mysql_query("SELECT * FROM users WHERE email='$email'"); $mem = mysql_fetch_array($sql); $que = mysql_query("SELECT * FROM quests") or die(mysql_error()); $quest = mysql_fetch_array($que); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript" language="javascript" src="ajax.js"></script> <link rel="stylesheet" href="http://www.lordoftheabyss.com/layout/default.css"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <? $room = $_GET['room']; ?> <title><? echo $room; ?></title> </head> <body bgcolor=black> <center> <? include 'links.php'; ?> </center> <table border="0" width="1000" cellpadding="6" cellspacing="5"> <tr> <td width="200" valign="bottom"><? include 'icons.php'; ?></td> <th width="650" bgcolor="#212121"><center><? echo $room; ?></center></th> <td width="200" rowspan="2" valign="top" bgcolor="#212121"><left><? include 'links2.php'; ?></left></td> </tr> <tr> <td width="200" valign="top"><? include 'panel.php'; ?></td> <td width="650" bgcolor="#000000" valign="top"> <div id="countPosts" style="height: 300px; width: 500px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div> </td> </table> <center> <? include 'links.php'; ?> </center> <? } ?> </body> </html> request.php <? include 'db.php'; $blah = mysql_query("SELECT * FROM chat WHERE room = '$room' ORDER BY id DESC LIMIT 20") or die(mysql_error()); while($chat = mysql_fetch_array($blah)){ echo "$chat[message]<br>"; } ?> ajax.js function createRequestObject() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // There is an error creating the object, // just as an old browser is being used. alert('There was a problem creating the XMLHttpRequest object'); } return req; } // Make the XMLHttpRequest object var http = createRequestObject(); function sendRequest(request) { // Open PHP script for requests var room = gup('room'); var url = 'request.php?room=' + room; http.open('get', 'url'); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4 && http.status == 200){ // Text returned FROM PHP script var response = http.responseText; if(response) { // UPDATE ajaxTest content document.getElementById("countPosts").innerHTML = response; setTimeout(countPosts,20); } } } function countPosts() { sendRequest('countPosts'); } anything put forward would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/ Share on other sites More sharing options...
almightyegg Posted September 11, 2007 Author Share Posted September 11, 2007 changed it a bit, there is only 1 room now so it doesn't send the $room to request.php anymore....yet it still doesn't work!! index.php - This is the only relevant code <div id="show()" style="height: 300px; width: 500px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div> request.php - <? include 'db.php'; $blah = mysql_query("SELECT * FROM chat ORDER BY id DESC LIMIT 20") or die(mysql_error()); while($chat = mysql_fetch_array($blah)){ echo "$chat[message]<br>"; } ?> ajax.js - function createRequestObject() { var req; if(window.XMLHttpRequest){ // Firefox, Safari, Opera... req = new XMLHttpRequest(); } else if(window.ActiveXObject) { // Internet Explorer 5+ req = new ActiveXObject("Microsoft.XMLHTTP"); } else { // There is an error creating the object, // just as an old browser is being used. alert('There was a problem creating the XMLHttpRequest object'); } return req; } // Make the XMLHttpRequest object var http = createRequestObject(); function sendRequest() { http.open('get', 'request.php'); http.onreadystatechange = handleResponse; http.send(null); } } function show() { sendRequest('show'); } function handleResponse() { if(http.readyState == 4 && http.status == 200){ // Text returned FROM PHP script var response = http.responseText; if(response) { // UPDATE ajaxTest content document.getElementById("show").innerHTML = response; setTimeout(show,20); alert(OMG); } } Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-346262 Share on other sites More sharing options...
Philip Posted September 13, 2007 Share Posted September 13, 2007 What does running just request.php say? Does it echo anything out (try putting something in the DB, then checking it) Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-347704 Share on other sites More sharing options...
almightyegg Posted September 13, 2007 Author Share Posted September 13, 2007 I've got something in the DB but it isn't echoing it out..... Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-347865 Share on other sites More sharing options...
almightyegg Posted September 13, 2007 Author Share Posted September 13, 2007 oops,t realised what yoiu meant... when opening request.php on it's own: TEGHBKJMMKLW (Which was me adding a random row for testing purposes ) Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-347868 Share on other sites More sharing options...
almightyegg Posted September 18, 2007 Author Share Posted September 18, 2007 Can anyone help me with this?? Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-350656 Share on other sites More sharing options...
almightyegg Posted September 24, 2007 Author Share Posted September 24, 2007 nobody? Quote Link to comment https://forums.phpfreaks.com/topic/68744-was-following-tutorial/#findComment-354142 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.