Jump to content

Opening an AJAX element inside an AJAX element?


frankhaugen

Recommended Posts

I'm new to AJAX so forgive me if I don't no the lingo fully.

 

I am working on a website, I have turned to AJAX from iframes, and I've hit a snag, which maybe some of you can help me with. Using this code:

<script class="AJAXscript" type="text/javascript">
function loadXMLDoc2()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	}
  }
xmlhttp.open("GET","test.php",true);
xmlhttp.send();
}
</script>

<button type="button" onclick="loadXMLDoc2()">hi</button>

I open a php file, which in turn have links I need to use, using the "AJAX div element" it is inside of to present the second php document, but using the same code, of course with different names, it just isn't responsive. Any ideas??

 

 

Thanks for any help!!

 

 

here are code in my test project I'm using to figure this out:

 

index.php:

<!DOCTYPE HTML>
<html>
<head>
	<title>
		Lorem ipsum dolor sit amet
	</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<script type="text/javascript">
		function loadXMLDoc()
		{
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
			}
		  }
		xmlhttp.open("GET","test2.php",true);
		xmlhttp.send();
		}
	</script>
</head>
<body>
	<div id="wrapper">
		<div id="banner">

		</div>
		<div>
			<button type="button" onclick="loadXMLDoc()">Change Content</button>
		</div>
		<div>
			<div id="myDiv"><h2>Let AJAX change this text</h2></div>

		</div>
		<div></div>
		<div></div>
	</div>
</body>
</html>

 

test2.php:

<script class="AJAXscript" type="text/javascript">
function loadXMLDoc2()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
	}
  }
xmlhttp.open("GET","test3.php",true);
xmlhttp.send();
}
</script>

<button type="button" onclick="loadXMLDoc2()">hi</button>

 

test3.php:

<?php
echo "success";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.