为什么这个ajax调用没有读取我的内部php?
太多的编辑无法跟踪,但我简化了问题。我的index.php中有以下代码:为什么这个ajax调用没有读取我的内部php?,php,ajax,Php,Ajax,太多的编辑无法跟踪,但我简化了问题。我的index.php中有以下代码: <div class="calendar_top"> <?php include(SITE_ROOT . "/includes/sub_top_divs.php"); ?> </div> <table class="tablebodycontainer"><tr><td> <?php include(SITE_ROOT . "/inc
<div class="calendar_top">
<?php
include(SITE_ROOT . "/includes/sub_top_divs.php"); ?>
</div>
<table class="tablebodycontainer"><tr><td>
<?php
include(SITE_ROOT . "/includes/view-monthly-calendar-ajax.php");
?>
</td></tr></table>
<?php include(SITE_ROOT . "/includes/copyright.php"); ?>
</div>
上面的副标题包含导航链接:
includes/subtop-divs.php:
<?php
//include(SITE_ROOT . "/includes/set-variables.php");//dateFormat($date)
echo "<table class='navtabs' cellpadding='0' cellspacing='0'>";
echo "<tr><td class='right'>";
echo buildMenuNavigation($currentPageIndex);
echo '</td></tr></table>';
?>
以下是BuildMenunigation函数:
function buildMenuNavigation($currentIndex=0) {
$navtabs = array(
'0'=>array('Monthly'=>'index.php'),
'1'=>array('Daily'=>'agenda.php'),
'2'=>array('Admin'=>'admin/view-timelines.php'),
'3'=>array('Help'=>'help.php'),
);
$sep = '<li> | </li>';$builtNav=array();
foreach($navtabs as $index=>$tablinks) {
foreach($tablinks as $key=>$value) {
$class='';
if($index==$currentIndex) {
$class=' class="selected"';
}
//pr($value);
$builtNav[] = '<li><a href="' . SITE_URL . '/' . $value.'"' . $class .'> '.$key.' </a></li>';
}
}
return '<ul>' . implode($sep,$builtNav) . '</ul>';
}
函数buildMenuNavigation($currentIndex=0){
$navtabs=数组(
“0'=>数组('Monthly'=>'index.php'),
'1'=>array('Daily'=>'agenda.php'),
“2'=>数组('Admin'=>'Admin/view timeline.php'),
'3'=>array('Help'=>Help.php'),
);
$sep='| ';$builtNav=array();
foreach($navtabs作为$index=>$tablinks){
foreach($tablinks as$key=>$value){
$class='';
如果($index=$currentIndex){
$class='class='selected';
}
//公共关系(价值);
$builtNav[]='';
}
}
返回“”。内爆($sep,$builtNav)。“
”;
}
切换页面时实际更改的唯一数据是上述内容:
<?php
include(SITE_ROOT . "/includes/view-monthly-calendar-ajax.php");
?>
因此,这似乎是ajax的完美候选
以下是/includes/view-monthly-calendar-ajax.php的内容:
<?php
$counter = 0;
?>
<table class="tabbody">
<tr>
<td class='head unselectable'>Sun</td>
<td class='head unselectable'>Mon</td>
<td class='head unselectable'>Tue</td>
<td class='head unselectable'>Wed</td>
<td class='head unselectable'>Thu</td>
<td class='head unselectable'>Fri</td>
<td class='head unselectable'>Sat</td>
</tr>
<tr>
<?php
//echo $year."-".$month."-";
$flag = 0;
$daysInrow = 0;
for($i = 1; $i < $numDays+1; $i++, $counter++)
{
$daysInrow++;
$zero = "";
if($i < 10)
{
$zero = "0";
}
$t_date = $year."-".$month."-".$zero.$i;
//$t_date = "$year-$month-$i";
$timeStamp = strtotime($t_date);
$eventID = 0;
$eventName = " ";
$bgColor = "";
$funcBG = "setbgcolorMonth($i);";
if($i == 1)
{
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++)
echo "<td class='tddaybox'></td>";
}
if($counter % 7 == 0)
{
$daysInrow = 1;
echo "</tr><tr>";
}
if(date("w", $timeStamp) == 0)
if($i == date("d") && $month == date("m") && $year == date("Y"))
$class = "class='today'";
else
$class = "class='weekend'";
else
if($i == date("d") && $month == date("m") && $year == date("Y"))
$class = "class='today'";
else
$class = "class='normal'";
$numric_time = getNumericTime($_SESSION['userData']['timezone']);//Get the numeric timezone
$query = "SELECT * FROM events WHERE date(convert_tz(StartDate,'+00:00','". $numric_time."'))='".$t_date."' AND UserID='" . $_SESSION['userData']['UserID'] ."' ORDER BY PTLType ASC";
//br();
$result = mysql_query($query);
if(mysql_num_rows($result))//cursor:hand;cursor:pointer;width:112px;
{
$funcBG = "";
echo "<td valign='top' class='a_cursor_width tddaybox' id='day$i' onclick='setbgcolorMonth($i)'>";
echo "<div class='td_overlow'>";
echo '<table style="width:100%;border:0;">';
echo '<tr class="rowColor"><td '.$class.'><div class="div_left"><a href="'.SITE_URL.'/agenda.php?date='.$year.'-'.$month.'-'.$zero.$i.'">'.$i.'</a></div><div class="div_left_80" onclick="'.$funcBG.' get_event_popup(window.event, this, \''.SITE_URL.'/event-popup.php\', \'eventID='.$eventID.'\', \'date='.$date.'\', \'day='.$i.'\', \'type=M\');return false"> </div></td></tr>';
while($row = mysql_fetch_assoc($result))
{
$eventID = $row['EventID'];
$parentEventID = $row['ParentEventID'];
$eventName = stripslashes($row['EventName']);
$PTLType = $row['PTLType'];
$textclass = "title4";
$onclick_call = 'get_event_popup(window.event, this, \''.SITE_URL.'/event-popup.php\', \'eventID='.$eventID.'\', \'date='.$date.'\', \'day='.$i.'\', \'type=M\')';
if($PTLType != 0) {
$onclick_call = 'get_event_popup(window.event, this, \''.SITE_URL.'/timeline-popup.php\', \'eventID='.$eventID.'\', \'parentEventID='.$parentEventID.'\', \'type=M\')';
$bgColor = "";
$textclass = "redtext";
if($PTLType == 3) {
$textclass = "bluetext";
$display = "none";
} else {
$display = "block";
}
$event_name_wrapped = '<div>'.$eventName.'</div>';
} else {
$textclass = "mainEvent";
$display = "block";
$event_name_wrapped = '<div>'.$eventName.'</div>';
}
echo '<tr><td onclick="'.$onclick_call.';return false;" class="'.$textclass.' a_cursor" title="'.$eventName.'" style="display:'.$display.';">'.$event_name_wrapped.'</td></tr>';
}
echo '<tr><td onclick="get_event_popup(window.event, this, \''.SITE_URL.'/event-popup.php\', \'eventID=0\', \'date='.$date.'\', \'day='.$i.'\', \'type=M\');return false;" class="a_cursor"> </td></tr>';
echo "</table>";
echo "</div>";
echo "</td>";
}
else
{
echo '<td id="day'.$i.'" height="80" valign="top" onclick="'.$funcBG.' get_event_popup(window.event, this, \''.SITE_URL.'/event-popup.php\', \'eventID='.$eventID.'\', \'date='.$date.'\', \'day='.$i.'\', \'type=M\');return false;" class="tddaybox a_cursor">';
echo '<table style="width:100%;">';
echo "<tr class='rowColor'><td $class>$i</td></tr>";
echo "<tr><td> </td></tr>";
echo "</table>";
echo "</td>";
}
}
for($l=0;$l<7-$daysInrow;$l++)
{
echo "<td class='tddaybox'> </td>";
}
?>
</tr>
</table>
<?php
/*
if(isset($divRed))
{
$divRed = implode(",",$divRed);
echo "<div id='divRed1' style='display:none'>$divRed</div>";
}
else
{
echo "<div id='divRed1' style='display:none'>0</div>";
}
if(isset($divBlue))
{
$divBlue= implode(",",$divBlue);
echo "<div id='divBlue1' style='display:none'>$divBlue</div>";
}
else
{
echo "<div id='divBlue1' style='display:none'>0</div>";
}
if(isset($divMainEvent))
{
$divMainEvent= implode(",",$divMainEvent);
echo "<div id='divMainEvent1' style='display:none'>$divMainEvent</div>";
}
else
{
echo "<div id='divMainEvent1' style='display:none'>0</div>";
}
*/
?>
<div id='gig1' style='display:none'>0</div>
<div id='todo1' style='display:none'>0</div>
<div id='completed1' style='display:none'>1</div>
<input type="hidden" id='lastselectedday' value='' />
太阳
周一
星期二
结婚
清华大学
星期五
坐
PHP代码由服务器处理;除非web服务器出现故障,否则浏览器永远不会看到它。PHP在数据发送到客户端之前进行了预处理。服务器解析并执行php代码,只发送代码输出的内容。如果你想得到完整的文件,你需要让它不被php处理,例如,通过将文件扩展名重命名为其他文件。首先,你不应该通过Ajax提取
元素,它们不会被解释,如果是,它们会在第二次请求时破坏所有内容
首先在浏览器中调用/Dev2/includes/view monthly calendar ajax.php
,进行一些调试。查看您所获得的源代码。PHP在交付文档之前运行,因此无法提取HTML,但无法提取PHP生成的内容。它们是一个实体
您的PHP代码中可能存在导致错误输出的错误,或者您的PHP代码根本没有被解释,这很容易发现,因为原始PHP源代码将出现在文档的源代码中(这永远不会发生)。您应该实现另一个PHP页面,例如
getData('getPHP.php?page=/Dev2/includes/view-monthly-calendar-ajax.php', 'targetdic');
然后在该页面中,您需要实现一个方法以字符串形式加载php文件并返回它。目前php被解释为您所期望的样子。我是否误解了什么,或者您是否试图返回实际的php代码?您的getData
函数在哪里?是的,我-我从您的回答中猜测,这不可能是我这样做的?getData在我的脑海中。我把它添加到问题中。更新:嗯,这可能是一个逐步调试的案例。您的变量是否正确,您是否在正确的位置获得正确的数据。。。您可以使用调试器,或者只进行testecho
输出。我可以将这些脚本移动到主页头,这样就没有问题了。当我在浏览器中加载/Dev2/includes/view-monthly-calendar-ajax.php时,我得到的源代码与我在问题中提出的源代码完全相同(没有php)。问题是,我需要解释php,以便在通过ajax调用月历时构建月历…编辑:我知道实际的代码是有效的,因为我现在在一个单独的页面中使用它-我只是尝试使用ajax,不必导航到这个新页面,而只需替换内容。在您的php代码中,您正在为($i=1;$i<$numDays+1;$i++,$counter++)运行循环,`$numDays
来自哪里?因为如果没有设置或为零,循环将不会运行一次;事情似乎没有改变。我觉得Paul Creasy的思路是正确的,我需要让ajax调用实现另一个页面来加载php信息,然后再加载它?我现在只需要想一想该怎么做……幽默我,然后高兴地试试$numDays=10
。)不幸的是,我的输出没有改变。我确信这是一件很简单的事情,但我还是太新了,无法完全“理解”。因为这是一个更复杂的问题,我通常会在这里尝试解决这些问题,我将添加完整的索引页,看看是否有明显的问题…我希望没有人介意!这是有道理的…我需要php代码来构建日历,它将填充被替换的div内容。你能告诉我怎么做吗?如果你希望在浏览器中处理php,你不能。我只是希望这样做。什么可以做到这一点?
getData('getPHP.php?page=/Dev2/includes/view-monthly-calendar-ajax.php', 'targetdic');