LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-23-2006, 07:28 PM   #1
jon23d
Member
 
Registered: May 2006
Location: Kennewick, WA - USA
Distribution: Ubuntu
Posts: 129

Rep: Reputation: 15
ajax multiple streams colliding


Hi. I'm trying to get an ajax application to handle mulitple requests simultaneously, but it obviously is not working. I realized this was happening so I created a function to create a new XMLHttpRequest object for each request that would later be set to null and garbage collected. I think that my problem is that javascript does not accept objects by reference as a parameter to a function, so I am still having objects closed before other requests can read the results. Here are my functions:

Code:
function createHTTPObject() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		var http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		var http = new XMLHttpRequest();
	}
	return http;
}

function phpCall() {
	return 'includes/ajax.php?SSID=' + readCookie('sessionID') + '&userID=' + readCookie('userID') + '&action=';
}


function get(action, div, objHTTP) {
	if (!objHTTP) {
		http = createHTTPObject();
		http.open('get', phpCall() + action);
		http.onreadystatechange = function() { get(action, div, http); };
		http.send(null);
	} else {
		if (objHTTP.readyState == 4) {
			var response = objHTTP.responseText;
			checkLogin(response);
			document.getElementById(div).innerHTML = response;
			objHTTP = null;
		}
	}
}
So, the problem lies when my page is constructed with:

Code:
<body onload="get('homePage', 'content'); get('mainMenu', 'mainMenu');">
Only one call is getting through, usually the second. Sometimes both divs will receive the output of the second call. Am I correct here, and if so - is there a solution to this?
 
Old 09-26-2006, 08:51 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
In the code you posted, 'get' takes three arguments, but you only supply it with two in the onload.
 
Old 09-26-2006, 09:11 AM   #3
jon23d
Member
 
Registered: May 2006
Location: Kennewick, WA - USA
Distribution: Ubuntu
Posts: 129

Original Poster
Rep: Reputation: 15
I'm not sure if it has the same name in javascript, but I use that as constructor overloading.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Eclipse Ajax Toolkit Framework and Ajax tools LXer Syndicated Linux News 0 05-12-2006 12:21 PM
Can't have multiple audio streams Dillbilly Linux - General 3 03-05-2006 10:16 PM
LXer: Mastering Ajax, Part 3: Advanced requests and responses in Ajax LXer Syndicated Linux News 0 02-16-2006 06:46 AM
multiplexing multiple audio streams David the H. Linux - Software 1 12-31-2005 01:18 PM
Are sound chips capable of multiple sound streams? SGFHK321 Linux - Hardware 1 07-29-2004 04:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration