954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ajax switch

Hello everyone,

The ajax+php part worked well independently. When I created a switch (because I want different information from database to be displayed in different tabs), it does not go into the xmlHttp.onreadystatechange=function(). I tried all possible variations, and looked online for hours.

Can anyone help please?
Thank you

var moduleidd;
var xmlHttp;
function loadModules(moduleid, birdid)
{

switch (moduleid)
{
case "contentA":
document.getElementById("contentA").innerHTML = "Hello";


case "contentB":
{
	
xmlHttp=GetXmlHttpObject();
var url= "contentB.php";
url=url+"?q="+birdid;
url=url+"&sid="+Math.random();

xmlHttp.onreadystatechange=function(){

		
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	document.getElementById("contentB").innerHTML = "test test test 123";
	 var a = xmlHttp.responseText;
document.getElementById("contentB").innerHTML = a;

 } 
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

};

};	

case "contentC":
case "contentD":
case "contentE":

}

}



function GetXmlHttpObject()
{
xmlHttp=null;


try{
	//Firefox, Opera 8.0+, Safari
	xmlHttp=new XMLHttpRequest();
}
catch (e)
{
	//Internet Explorer
	try
	{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}
return xmlHttp;
}
Mylena
Light Poster
30 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Are you sure, did you put an alert() in the function to see?

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

thanks for your reply,

yes, i put alert() function and it did not display. When i put alert() just before the no-working function, the alert displays. it's strange,...

Mylena
Light Poster
30 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

OOps, i solved it now, the closing brackets were wrongly aranged... how silly!

Mylena
Light Poster
30 posts since Jul 2007
Reputation Points: 10
Solved Threads: 1
 

Oh, you did fix it, OK cool.

R0bb0b
Posting Shark
998 posts since Jun 2008
Reputation Points: 358
Solved Threads: 89
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You