# Other Programming > AJAX >  [RESOLVED] I need help with AJAX

## cloud1

My AJAX code is not working please help.

Please *ignore syntax error(s)* just get the idea.

Below is my AJAX code:



```
/**
 * @author cloud
 */
var pointer;
function userStatus(method, url, asynchronus)
{
	/*
	* Data members/Field members
	*/
	pointer=this;
	this.MAX_HTTPRequestObjects=4;
	this.log=document.getElementById("logMessages");
	this.url=url;
	this.method=method;
	this.asynchronus=asynchronus;
	this.index=0;
	this.XMLHTTPRequestObjects=new Array();
	this.memberName="";
	this.memberNumber="";
	this.memberData="";
	this.buddyData="";
	this.blogEntries="";
	/*
	 * Initialize data mebers/Field members
	 */
	this.getXMLHTTPRequestObjects();
	this.getMemberData();
	this.getBuddyData();
	this.getBlogEntries();
}

UserStatus.prototype.getXMLHTTPRequestObjects = function(){
	// Is it for Firefox, Safari, Opera, etcs ?
	try 
	{
		for (var i = 0; i < pointer.MAX_XMLHTTPRequestObjects; i++) this.xmlHTTPRequestObjects[i] = new XMLHttpRequest();
	} 
	catch (e) 
	{
		/*
		 * It is for Internet Explorer ?
		 */
		try 
		{
			for (var i = 0; i < pointer.MAX_XMLHTTPRequestObjects; i++) pointer.xmlHTTPRequestObjects[i] = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				for (var i = 0; i < pointer.MAX_XMLHTTPRequestObjects; i++) pointer.xmlHTTPRequestObjects[i] = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) 
			{
				window.alert("Your browser does not support AJAX.");
			}
		}
	}
};

UserStatus.prototype.getData(url, method, asynchronus)
{
	this.XMLHttpRequestObjects[this.index].onreadystatechange=this.processData;
	this.XMLHttpRequestObjects[this.index].open(method.toUpperCase(), url, asynchronus);
	this.XMLHttpRequestObjects[this.index].send(null);	
};

UserStatus.prototype.processData=function()
{
if (pointer.index==xml.MAX_XMLHTTPRequestObjects-1) return;	
if (pointer.xmlHTTPRequestObjects[pointer.index].readyState==0) pointer.logMessage("Request not initialize.");
	else if (pointer.xmlHTTPRequestObjects[pointer.index].readyState==1) pointer.logMessage("Request been setup.");
	else if (pointer.xmlHTTPRequestObjects[pointer.index].readyState==2) pointer.logMessage("Request has been sent.");
	else if (pointer.xmlHTTPRequestObjects[pointer.index].readyState==3) pointer.logMessage("Request is process.");
	else if (pointer.xmlHTTPRequestObject.readyState==4)
	{
		if (pointer.index==0) parseMemberData(pointer.xmlHTTPRequestObject[pointer.index].responseText);
		else if (pointer.index==1) parseBuddyData(pointer.xmlHTTPRequestObject[pointer.index].responseText);
		else if (pointer.index==2) parseBlogentries(pointer.xmlHTTPRequestObject[pointer.index].responseText);
	}
	pointer.index++;
};

UserStatus.prototype.getMemberData=function (method, url, aysynchronus)
{
	this.getData(method, url, asynchronus);
};

UserStatus.prototype.getBuddyData=function (method, url, asynchronus)
{
	this.getData(method, url, asynchronus);
};

UserStatus.prototype.getBlogEntries=function (method, url, asynchronus)
{
	this.getData(method, url, asynchronus);
};

UserStatus.prototype.parseMemberData=function (memberData)
{
	/*
	 * Parse member data in here
	 */
};

userStatus.prototype.parseBuddyData=function (buddyData)
{
	/*
	 * Parse buddy data in here
	 */
};

UserStatus.prototype.parseBlogEntries=function (blogEntries)
{
	/*
	 * Parse blog entries in here
	 */
};

UserStatus.prototype.logMessage=function (message)
{
	this.log.value=this.log.value+messsage+"\n";
}
```

Here is one of the error:


```
[Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame ::"  data: no]
```

Here is the other error:



> *I get different responses for different requests*


I need help resolving these error.




> I solved the problem. The idea was right, but there was a logical error.
> I should have used a loop to check an array of xhr objects and use the loop
> counter as an index to direct the appropriate responses to the appropriate destinations.

----------

