/    Sign up×
Community /Pin to ProfileBookmark

[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 .[/COLOR][/COLOR]

[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]

[B]What do I need to add to the viewIt() function in ajax.js to make this possible?[/B]

[B][U]ajax.js[/U][/B]

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[/U][/B]

[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>[/code]

[B][U]classes.php[/U][/B]

[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>&nbsp;</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]

[/code]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @porsche21 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...