I've been asking similar questions here today, but I'm seeing I think the issue is with how I am calling my data?
I'm trying to replace a nav bar with ajax that will load contents into a div.
The nav bar is this:
<ul>
<li><a href="javascript:void(0)" onclick="getData('/includes/view-monthly-calendar-ajax.php', 'targetDiv')">Monthly</a></li>
<li><a href="javascript:void(0)" onclick="getData('/includes/agenda-ajax-include.php', 'targetDiv')">Daily</a></li>
<li><a href="javascript:void(0)" onclick="getData('/includes/hello-include.php', 'targetDiv')">Admin</a></li>
<li><a href="javascript:void(0)" onclick="getData('/includes/view-monthly-calendar-ajax.php', 'targetDiv')">Help</a></li>
</ul>
Then I have this to replace the div:
<div id="targetDiv"></div>
the getData function is an innerHTML request:
<script language = "javascript">
function getData(dataSource, divID)
{
$.ajax({
url: dataSource,
dataType: 'html',
success: function(data) {
$('#' + divID).html(data);
}
});
}
</script>
When I click the nav links, the HTML loads into the div, but the contents of my include files also contain PHP functions and jQuery that needs to execute when being loaded and they are just ignored. I've seen this question asked a lot here, but these seem to only relate to jQuery?
To be clear, when I click the nav links, I get a 200 OK in firebug console, but only HTML is coming back and populating div.
Here is my most recently cleaned include file with changes from Jonathan's suggestions. At this point, I am getting output up the the </tr>
after the help button (line 15) but no output past that...
<?php
session_start();
?>
<table width='100%' border='0'>
<tr class='twentyfivepxheight'><td></td></tr>
<tr>
<td width='40%' valign='top'>
<div class='left_agenda_items'>
<table width='80%' align='center' border='0'>
<tr class='twentyfivepxheight'>
<td align='left' class='title5 bottompadding unselectable'>Daily Agenda<a href="javascript:void(0)" class="supernote-click-note1">
<img src="/images/help-sm.jpg" alt="Help Button" /></a>
</td>
</tr>
<?php
$numric_time = getNumericTime($_SESSION['userData']['timezone']);
$query = "SELECT * FROM events WHERE date(convert_tz(StartDate,'+00:00','". $numric_time."'))='$currentDate' AND UserID='" . $_SESSION['userData']['UserID'] ."' ORDER BY StartTime";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result))
{
$eventID = $row['EventID'];
$eventName = $row['EventName'];
$startDate = $row['StartDate'];
$description = $row['Description'];
$assignedTo = $row['AssignedTo'];
$PTLType = $row['PTLType'];
$parentEventID = $row['ParentEventID'];
$textclass = "greentext unselectable";
$text = "Main event";
//$url = SITE_URL ."/agenda-view-event.php?eventID=$eventID&date=$currentDate&day=$i&type=A&date=$currentDate";
$url = SITE_URL ."/agenda-view-event.php";
if($PTLType == 2) // To do's
{
//$divRed[] = $eventID;
$url = SITE_URL ."/agenda-view-timeline.php";
$textclass = "redtextDaily unselectable";
$text = "To do";
$html_todos .= '
<tr id="redtext' . $eventID . '">
<td id="rowbox'.$eventID.'" class="'. $textclass . '" width="30%" onclick="get_event_popup(\'' . $url . '\', \'agendaViewDiv\', \'agendaLoader\', \'eventID='.$eventID.'\', \'parentEventID='.$parentEventID.'\', \'type=A\', \'date='.$currentDate.'\');setbgagendabox(\''.$eventID.'\');return false">
' . $eventName . ' - (' . $text . ')
</td>
</tr>';
}
elseif($PTLType == 3) //Completed
{
//$divBlue[] = $eventID;
$url = SITE_URL ."/agenda-view-timeline.php";
$textclass = "blueTextDaily unselectable";
$text = "Completed";
$html_completed .= '<tr id="bluetext' . $eventID . '"><td style="display:none;" id="rowbox'.$eventID.'" class="' . $textclass . '" width="30%" onclick="get_event_popup(\'' . $url . '\', \'agendaViewDiv\', \'agendaLoader\', \'eventID='.$eventID.'\', \'parentEventID='.$parentEventID.'\', \'type=A\', \'date='.$currentDate.'\');setbgagendabox(\''.$eventID.'\');return false">' . $eventName . ' - (' . $text . ')</td></tr>';
} else { //main events
//$divMainEvent[] = $eventID;
$html_main_events .= '<tr id="mainEvent' . $eventID . '"><td id="rowbox'.$eventID.'" class="' . $textclass . '" width="30%" onclick="get_event_popup(\'' . $url . '\', \'agendaViewDiv\', \'agendaLoader\', \'eventID='.$eventID.'\', \'date='.$currentDate.'\', \'day='.$i.'\', \'type=A\', \'date='.$currentDate.'\');setbgagendabox(\''.$eventID.'\');return false">' . $eventName . ' - (' . $text . ')</td></tr>';
}
}
echo $html_main_events . $html_todos . $html_completed;
} else {
?>
<tr>
<td>
<span class="a_dateformat">You have no agenda items due today!</span>
</td>
</tr>
<?php
}
?>
</table>
</div>
<input type="hidden" id='lastselected' value='' style="" />
</td>
<td class='verticalborder'> </td>
<td width='59%' valign="top" align="center">
<div id="agendaLoader" style="display:none;">
<img src="images/ajax-loader-orange.gif" alt="wait" />
</div>
<div id="agendaViewDiv" style="display:none;"></div>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</table>
But see how I commented out the jQuery to make it work?
If that is not commented out, I don't get any output. The problem is that I need that jQuery to properly build the page.