[COLOR=”Blue”]Ok so I am still trying to understand AJAX hopefully someone can help me with this.[COLOR=”Black”] I have (3) files ajax.js, index.php and classes.php .
[B]On my index.php I call the object Menu() to display my menu links from the classes.php page. When I click on the link I want to use ajax to display the MapIt() function in the <div> area. But it still needs to go through the viewmaps process located on the classes.php page.
[B]What do I need to add to the viewIt() function in ajax.js to make this possible?
[B][U]ajax.js
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
function loadingMessage(){
document.getElementById(“ajaxDiv”).innerHTML = “Loading please wait…”;
}
function clearResults(){
document.getElementById(“ajaxDiv”).innerHTML = “”;
}
function handleStateChange(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status ==200){
document.getElementById(“ajaxDiv”).innerHTML = xmlHttp.responseText;
}
}
}
function viewIt(){
createXMLHttpRequest();
loadingMessage();
var url = “classes.php”;
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open(“GET”, url + new Date().getTime(), true);
xmlHttp.send(null);
}
[B][U]index.php
[code=php]<?php
include(‘header.php’);
require_once(‘includes/DbConnector.sybase.php’);
$sybconnect=new sybaseDbConnector();
require_once(‘includes/DbConnector.mysql.php’);
$connect=new myDbConnector();
?>
<table height=”100%” bgcolor=”Silver” border=”1″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td>
<?php
$instance = new CellName();
$instance->Menu();
?>
<div id=”ajaxDiv” style=”padding-left:17px;background-color:#CC9933;”>
THIS IS WHERE THE RESULTS WILL GO
</div>
</td>
</tr>
</table>
[B][U]classes.php
[code=php]<?php
class CellName
{
function Menu()
{
if (isset($this)) {
echo ‘<br><a href=”#” onclick=”viewIt();”>View Maps</a><br>
<a href=”index.php?option=cellname&task=addmap”>Add Map</a><br>
<a href=”index.php?option=cellname&task=editmap”>Edit Map</a><br>
<a href=”index.php?option=cellname&task=viewedits”>View Alterations</a><br>’;
} else {
echo “$this is not defined.n”;
}
}
}
class Maps
{
function viewmaps()
{
GLOBAL $sybconnect;
$sql=”select distinct cellname,centname from celltech order by cellname”;
$link=$sybconnect->query($sql);
$i=0;
while($row=$sybconnect->fetchArray($link)){
$output[$i][‘cellname’]=$row[‘cellname’];
$output[$i][‘centname’]=$row[‘centname’];
$i++;
}
//$connect->close();
return $output;
}
function MapIt(){
if(isset($this)){
//user wants to see the maps
$maps = new Maps();
$displaysite = $maps->viewmaps();
?>
<div style=”height:400px;overflow:auto”>
<table>
<tr>
<th>Cell Name</th>
<th> </th>
<th>Centname</th>
</tr>
<?php
for($i=0;$i<count($displaysite);$i++){
?>
<tr>
<td><strong><?php echo $displaysite[$i][‘cellname’];?> (<a href=”http://<?php echo $_SERVER[‘SERVER_NAME’].$_SERVER[‘PHP_SELF’];?>?option=cellname&task=editmap&cellname=<?php echo $displaysite[$i][‘cellname’];?>”>Edit</a>)</strong></td>
<td>maps to</td>
<td><strong><?php echo $displaysite[$i][‘centname’];?></strong></td>
</tr>
<?php
}
?>
</table>
</div><?php
}
}
[/code]