Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Chat issues.

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I was wondering if anyone wouldn't mind helping me out a bit with this javascript. I guess it needs "optimization" as well as some adjustments that will keep an error from showing up in FF and an "Out of memory" error in IE.

I'm using AJAX and PHP to get my data to update and constantly monitor new messages. It "works" in Firefox, but the Error Console is continuously repeating:
Code:
Error: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: [URL unfurl="true"]http://www.blasterstudios.com/chat/admin_speak.php?session=23[/URL] :: showIt :: line 142"  data: no]
Source File: [URL unfurl="true"]http://www.blasterstudios.com/chat/admin_speak.php?session=23[/URL]
Line: 142
This is the looping function that causes these billions of errors and i've commented "line 142":
Code:
function showIt(url,method,session){
	var xmlhttp=false; 
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e) {
		try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open(method, url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if( content != "" && content.length > 0 ){
				document.getElementById('admin_chat').innerHTML = content;
				objDiv = document.getElementById('admin_chat');
				objDiv.scrollTop = objDiv.scrollHeight;
			}
			updateChatLog();
		}
	}
	xmlhttp.send(null);
	xmlhttp.send('');  //line 142
	return;
}

When I load this one up in IE -
Code:
function showIt(url,method){
	var xmlhttp=false; 
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e) {
		try {
			xmlhttp = new
			ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	xmlhttp.open(method, url, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if( content != "" && content.length > 0 ){
				var objDiv = document.getElementById('chat_window');
				objDiv.innerHTML = content;
				objDiv.scrollTop = objDiv.scrollHeight;
			}
			//updateChatLog();
		}
	}
	//xmlhttp.send('');
	xmlhttp.send(null);
	//return;
}
I get:
Code:
Out of Memory on line: 136
which is this line:
xmlhttp.open(method, url, true);

So basically, what I'm getting at is there is something seriously wrong that I don't quite understand. I've figured out that the "return" at the end of both functions is going to need to be commented out, so I can do other functions after this ajax function. I've read in a few places about send('') and send(null). I'm not sure what the difference is or even what it's even doing. Also, this might be important. This is my looping function that is checking for new messages:
Code:
var t;
function updateChatLog(){
	showIt('listener.php?update','GET');
	t = setTimeout(updateChatLog(),100);
}
This obviously poses another problem that doesn't allow the user to "scroll up" to see older chat.

Anyway, I would appreciate someone that knows more about this helping me to understand this better and possibly make this work a lot smoother and no errors.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top