XMLhttp + PHP problems...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

XMLhttp + PHP problems...

Post by Todd_Z »

Code: Select all

session_start();

	header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); 
	header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" ); 
	header( "Cache-Control: no-store, no-cache, must-revalidate" ); 
	header( "Cache-Control: post-check=0, pre-check=0", false ); 
	header( "Pragma: no-cache" );
	
	header("Content-type: application/x-javascript");

Code: Select all

function checkKey ( evt ) {
	if ( evt.keyCode == 13 ) {
		writeToConversation( document.conv.msg.value );
		document.conv.msg.value = '';
	}
}

function getHTTPObject() {
	var xmlhttp;
	xmlhttp = false;       
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.overrideMimeType('text/html');
	} else if (window.ActiveXObject)
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	return xmlhttp;
}

xmlhttp = getHTTPObject();
isBusy = false;

function writeToConversation ( msg ) {
	try {
		url = "/Scripts/Conversation.php?c=<?= $_GET['rm']; ?>&m=" + msg;
		if ( isBusy ) xmlhttp.abort();
		isBusy = true;
		xmlhttp.open( "GET", url, true );
		xmlhttp.onreadystatechange=function() {
			if ( xmlhttp.readyState == 4 )
				updateConv();
			isBusy = false;
		}
		xmlhttp.send(null);
	} catch ( e ) { }
}

function updateConv ( ) {
	try { 	
		url = "/Scripts/Conversation.php?c=<?= $_GET['rm']; ?>";
		if ( isBusy ) xmlhttp.abort();
		isBusy = true;
		xmlhttp.open( "GET", url, true );
		xmlhttp.onreadystatechange=function() {
			if ( xmlhttp.readyState == 4 ) {
				i = document.getElementById( 'convo' );
				if ( i.length > 0 )
					i.innerHTML = xmlhttp.responseText;
				isBusy = false;
			}
		}
		xmlhttp.send(null);
	} catch ( e ) { }
	setTimeout( "updateConv()", 300 );
}

updateConv();
The previous code is the js that controls an online instant messenger. However, for some CRAZY reason, it crashes my fx on linux. Any ideas folks? The /Scripts/Conversation.php script is just the script that either writes to or reads the conversation.
Post Reply