Jump to content

Form


mortalc

Recommended Posts

Using an <iframe> is not a good idea. There is a better way of doing it. :) (Just kidding....I really don't know if there is or isn't)
Aa-ha! You almost had me there...Ok, I will correct those errors and get back to you. Thanks!
Link to comment
Share on other sites

it's might be setTimeOut. It might need to be written setTimeout. Also, you might want to change the time lapse to something other than 1 millisecond. Something reasonable might be 3000 (3 seconds). Also, you probably might want to consider writing the function it calls it between quotes, without the parens.

setTimeOut('check', 3000)

also, for the conditional check, why not just

if(Xrequest.responseText != x){}

just a few observations...oh yeah, also, instead of having this...

		<script type="text/javascript">			check();		</script>

you could just add () to the end of the function definition to have it execute right away, like

function check(){//code}();

Link to comment
Share on other sites

Ok, I have made all of the corrections, and it still isn't working. I've also discovered that newmsg.txt is being changed occasionally, but for a while now it has been the same.

Link to comment
Share on other sites

any errors on the page?maybe try setting the timeout to like 10 seconds?edit: post your code too.

Link to comment
Share on other sites

chist.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml">	<head>		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>				<script type="text/javascript" >			var Xrequest= new XMLHttpRequest();			function check()			{				var x;				Xrequest.open("GET", "newmsg.txt", true);				Xrequest.send();				if (!(Xrequest.responseText==x))					{						document.write(Xrequest.responseText + "\n\n");					}				x = Xrequest.responseText;				setTimeout(check, 3000);			}		</script>	</head>	<body>		<script type="text/javascript">			check();		</script>	</body></html>

chat.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml">	<head>		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>		<style type="text/css">			#msg {width:90%}			#post {width:10%}		</style>		<script type="text/javascript" >			var Xsend = new XMLHttpRequest();			function send()			{				var msg = document.getElementById("msg").value;				Xsend.open("GET", "chp.php?msg=" + msg, true);				Xsend.send();			}		</script>	</head>	<body>		<iframe src="chist.xhtml" width="100%" height="90%"></iframe>		<form action="" method="post">			<input id="msg" type="text" name="msg" />			<button id="post" onclick="send()">send</button>		</form>	</body></html>

and here is chp.php:

<?php$msg = $mybb->user['username']."\n".$_GET["msg"]; // ignore the mybb bit, it is just the username cookiefile_put_contents("newmsg.txt", $msg);?>

Link to comment
Share on other sites

Not N*Sync enough....you were 7 min behind me. :) :)
had to check it for errors first. some people around here are real nitpickers... :(:)
Link to comment
Share on other sites

if (!(Xrequest.responseText==x))					{						document.write(Xrequest.responseText + "\n\n");					}				x = Xrequest.responseText

i am not sure what it is checking for in if structure. i think you should check for Xrequest.readystateyou will only recive the response if its readystate is 4.and i think instead of doing document.write it will be good if you load the response in any container (eg <div>)and i think you should call the setTimeOut() outside the check() declaration.

Link to comment
Share on other sites

2. the if() function is to make sure the same thing isn't posted twice.
this is not suppose to do that.Xrequset.responseText only contain values when it have readystate 4. it proobably will show readystate lower than 4 (when conection has been established) if you do a alert(xrequest.readyState) it will show you what is going on. and that time Xrequest wont hold any responseText. you need to check on ready state change when it reaches the readystate 4. 4 means response is recived. and only after that you can work with the response.
Link to comment
Share on other sites

Ok, so I'll need something like if(Xrequest.readystate=4)?
you need to check something like...if(Xrequest.readystate==4) you need to usedouble equal to for comparison
And What about the problems I am having at writing to the document?
cause at that time probably Xreqest.responseText is empty. so it is not writing anything actualy.
Link to comment
Share on other sites

are you saying its not writing the text file?

Link to comment
Share on other sites

http://www.w3schools.com/ajax/ajax_xmlhttp...statechange.aspit should be defined before the request is made, and like birbal suggested, it would be best to write to the innerHTML of an element on the page rather than using document.write. so here is where you want to check for the value of responseText for equality based on the value returned, and update the page if it's different. also, are you saying you're still having issues with all messages actually be saved to the text document?
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...