Ajax没有返回任何属性<table> </table>

时间:2013-02-15 15:32:14

标签: php javascript ajax

这是相当奇怪的,而且相当复杂,我试图尽可能地解释它。我正在手工制作日历,计划开源采购等。我目前正在寻找谷歌日历的外观和感觉,因为它们似乎是最好的,但我确实计划在一个upping它+开源。一切都运行完美,除非我点击上个月,为了查看上个月,然后运行ajax查询,php返回新日历,但是当它呈现时渲染没有 ANY {{1除了那些元素还没有遇到任何想法?继承了一些代码/图片:

HTML:                    

<table>

redraw.php:

//function to use xml
function xml(){
 //need to set up xml to run php for query
   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("calendar").innerHTML= xmlhttp.responseText;
    }
  };
}

//function to select the previous month
function previousMonth(str){
//since this is the previous month we need to take month -1
var month = str - 1;
 //if it is already 1.. then it needs to be 12!
  if(str == 1)
  {
   month = 12;
  }
   //call xml
   xml()
   //send dat query
   xmlhttp.open("GET","redraw.php?month="+encodeURIComponent(month),true);
   xmlhttp.send();
}

继续描述最新情况:

应该是什么样子: start

第一次点击

onclick

js插入// draws the calendar function draw_calendar($month,$year){ // table headings $headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); $calendar= '<tr class="calendar-row"><td class="calendar-day-head" id = "cell" style = "min-width:150px;">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>'; // days and weeks vars now $days_last_month = date('t',mktime(0,0,0,$month-1,1,$year)); $running_day = date('w',mktime(0,0,0,$month,1,$year)); $days_in_month = date('t',mktime(0,0,0,$month,1,$year)); $days_in_this_week = 1; $day_counter = 0; $dates_array = array(); $today = date("d"); // row for week one $calendar.= '<tr class="calendar-row">'; // print "blank" days until the first of the current week for($x = 0; $x < $running_day; $x++) { $calendar.= '<td class = "calendar-day-prev" id = "cell" style = "min-width:150px;"><div class = "day-prev- number" style = "color:#929D9D">'.(($days_last_month -($running_day - 1)) + $x).'</div>'; $calendar.= str_repeat('<p>&nbsp;</p>',2); $calendar.= '</td>'; $days_in_this_week++; } // keep going with days.... for($list_day = 1; $list_day <= $days_in_month; $list_day++) { $calendar.= '<td class = "calendar-day" id = "cell" style = " min-width:150px;"'; //if the day is today we obviously need to have a differnet style for it... if($list_day == $today) { $calendar.= ' style = "background-color:#9494B8;font-weight:bol;">'; } else { $calendar.= '>'; } // add in the day number $calendar.= '<div class = "day-number">'.$list_day.'</div>'; // THIS IS WHERE I NEED TO QUERY ENTRIES PER DAY $calendar.= str_repeat('<p>&nbsp;</p>',2); $calendar.= '</td>'; if($running_day == 6) { $calendar.= '</tr>'; if(($day_counter+1) != $days_in_month) { $calendar.= '<tr class="calendar-row">'; } $running_day = -1; $days_in_this_week = 0; } $days_in_this_week++; $running_day++; $day_counter++; } // finish the rest of the days in the week if($days_in_this_week < 8 && $days_in_this_week != 1) { for($x = 1; $x <= (8 - $days_in_this_week); $x++) { $calendar.= '<td class = "calendar-day-after" id = "cell" style = " min-width:150px;"><div class = "day-post-number" style = "color:#929D9D;">'.$x.'</div>'; $calendar.= str_repeat('<p>&nbsp;</p>',2); $calendar.= '</td>'; } }; // final row $calendar.= '</tr>'; // all done, return result return $calendar; } //draw the calendar $year = date ('Y'); $month_title = date ('F'); //Sent variables if(!empty($_REQUEST['month'])) { $month_display = $_REQUEST['month']; } else { $month_display = date ('n'); } echo draw_calendar($month_display,$year); 的内容 kinda works

php返回的内容(这部分看似正确): bad

2 个答案:

答案 0 :(得分:1)

您无法在任何地方添加<table>代码

在你的php中,替换这一行:

$calendar= '<tr class="calendar-row"><td class="calendar-day-head" id = "cell" style = "min-width:150px;">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

使用:

$calendar= '<table><tr class="calendar-row"><td class="calendar-day-head" id = "cell" style = "min-width:150px;">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';

这一行:

return $calendar;

使用:

return $calendar . '</table>';

答案 1 :(得分:1)

document.getElementById("calendar").innerHTML= xmlhttp.responseText;

您正在将表格行插入div,而不是table。添加缺少的表标记或将数据附加到表中。

NITPICKS - 您有“标题单元格”但不使用这些元素。你没有使用thead和tbody。