2013-02-15 37 views
-2

这是相当奇怪的,并且相当复杂,我去尝试是最好的,我可以解释它。即时手动制作日历,计划开放采购等。我目前正在寻找谷歌日历的外观和感觉,因为它们似乎是最好的,但是我打算在增加它+开源。一切都只是当我点击前一个月,以查看上个月完美运行,那么阿贾克斯查询运行时,PHP返回新日历,但是当它使得它呈现不任何<table>元素除此之外还没有触及丝毫没有任何想法?继承人一些代码/图片:阿贾克斯不返回任何<table> atributes

HTML:

//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(); 
} 

redraw.php:

// 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); 

继承人的怎么回事一个很好的描述:

它应该看起来像: startonclick

什么是JS的插入<div id = "calendar"> kinda works

什么由PHP返回(这部分似乎是正确的): bad

+1

你尝试“重绘”在同一个月你在,看看同样的事情发生?我很想知道为什么你不使用jQuery的Ajax调用...会更简单的权利? – 2013-02-15 15:37:22

+0

所以如果'#calendar'是一个DIV,并且你的'draw_calendar'返回了一堆TR,那么TABLE应该从哪里来? – robertklep 2013-02-15 15:38:44

+0

@Perroloco不太熟悉jquery坦率地说,我从来没有多少运气。但无论如何,这仍然应该工作。我也尝试过跨浏览器。并回答你的问题,是的,无论发生什么 – Nick 2013-02-15 15:38:54

回答

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

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

挑剔 - 你有“标题单元格”,但你不th元素使用。你没有使用thead和tbody。

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>';