Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-25-2012, 02:16 AM   PM User | #1
programInMotion
New to the CF scene

 
Join Date: Feb 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
programInMotion is an unknown quantity at this point
Passing a variable in ajax request

I can't figure out why it's not working. I have a page that calls another page through an xmlhttp request, and I need it to pull a variable AND it's value. This is the code for the page that I need the variable to go to.

Code:
function openLockdownPage() 
{
	var xmlhttp;
	var lockdownCheck = "<?php echo $lockdownValue ?>";
	console.debug(lockdownCheck);
	// Code for IE7+, FireFox, Chrome, Opera, Safari
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
			
	//code for IE6, IE5
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			if (lockdownCheck == 1)
			{
				document.all[0].innerHTML = xmlhttp.responseText;
			}
		}	
	}
	
	xmlhttp.open("GET", "<?php echo HTML_ROOT_PATH ?>modules/dynamic-display/overrides/lockdown/lockdownCheck.php?"+lockdownValue,true);
	xmlhttp.send();

}
And then I call it in PHP like this:

Code:
$lockdownValue = isset($_GET['lockdownCheck']) ? isset($_GET['lockdownCheck']) : "The value cannot be found";
And then this is the code that pulls the variable from the database, and if the variable's value is set to 1, it replaces the innerHTML with another page.

Code:
<?php
	include("../../../../config.php");
	include("../../../../db.php");
	//Query Overrides table
	$query = "SELECT * FROM Overrides";
	$result = mysql_query($query) or die (mysql_error());

	//Check lockdown status
	$lockdownStatus = mysql_fetch_array($result);

	if ($lockdownStatus['active'] == 1)
	{
		echo '<body onload = "openLockdownPage();">';
	}
?>

<script type = "text/javascript">
function openLockdownPage()
{
	var lockdownValue = "<?php echo $lockdownStatus['active'] ?>";
	var xmlhttp;
	// Code for IE7+, FireFox, Chrome, Opera
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}

	// Code for IE6, IE5
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			if (lockdownValue == 1)
			{
				document.all[0].innerHTML = xmlhttp.responseText;
			}
		}
	}

	xmlhttp.open("GET", "../lockdown/lockdown.php",true);
	xmlhttp.send();
}
</script>
I'd be grateful for any sort of help on this, I've been working at this for a long time, and it's starting to bug me.
programInMotion is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:06 AM.


Advertisement
Log in to turn off these ads.