Hello,
I have the following problem with Ajax :
- The files I will mention here are copied at the end of this mail, so anyone can look if necessary.
- My intention is to bring the contents of SubOne.php into the area defined by the DIV tag named "MyDiv" when I
press the button (in main.php) and then use the "Form Button" inside SubOne.php to change the text from :
"This is the subwindow one. We did not get any message"
to :
"This is the subwindow one. We got a message"
But the last part does not work the way I want. When I push the "Form Button" the text changes, but it reloads
using the whole window. I want the text to change while staying in the MyDiv area and leaving alone the top part of
my main.php window.
Can someone tell me what I need to change to make it work.
Thanks in advance for any tip or suggestion.
Michel
---------------------- Here is the code ----------------------
================== Beginning of main.php ==================
<html>
<head>
<title>Main Window</title>
<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","SubOne.php",true);
xmlhttp.send();
}
</script>
</head>
<body>
This the main window.
<Input Type="SUBMIT" Value="Load SubOne into MyDiv" onClick="loadXMLDoc()">
<br>----------------------------------------------------------------<br>
<div ID='MyDiv'>
This the MyDiv space.
</div>
<br>----------------------------------------------------------------<br>
</body>
</html>
================== End of main.php ==================
================== Beginning of SubOne.php ==================
<html>
<head>
<title>Subwindow One</title>
</script>
</head>
<body>
This is the subwindow one.
<?php
$MSG=$_POST;
if ($MSG) echo "We got a message";
else echo "We did not get any message";
?>
<BR><BR>
<FORM METHOD='POST' ACTION='SubOne.php'>
<INPUT TYPE='SUBMIT' NAME='MSG' VALUE='Form Button'>
</FORM>
</body>
</html>
================== End of SubOne.php ==================