我有一个创建<div>
的JavaScript函数。它使用Ajax访问数据库,如果日期匹配则创建不同的<div>
。但是现在我想从与数据库匹配的JavaScript <div>
中获取'date'变量,并通过另一个PHP函数发送它,该函数获取该日期的所有条目并将它们回显给JQuery弹出窗口。我做错了什么,是否有比下面的代码更简单的方法?
第一次AJAX通话:
beforeMonth:function(date)
{
$.ajax({
type: "GET",
url: "getCalendarEvents.php",
dataType: "json",
data: "date="+date,
async: false, //stop rendering the calender until eventdates is changed.
success: function(json){
$.fn.ical.changeEventDates(json); //this function changes the eventdates
}
})
}
getCalendarEvents.php
include ("Includes/dbConnect.php");
$_GET['date'];
$query2 = "SELECT * FROM events";
$checkevent = mysqli_query($cxn,$query2) or die("Couldn't execute query!");
$dates = array();
while ($row2 = mysqli_fetch_array($checkevent))
{
$eventDate = $row2['eventDate'];
$eventName = $row2['eventName'];
$eventHost = $row2['host'];
$dates[$eventDate] = array('title' => $eventName, 'desc' => $eventHost);
}
echo json_encode(array("dates" => $dates));
exit;
JavaScript在单独的文件中(只是创建<div>
的函数):
if(!datejson)
{
options.beforeDay(formatdate);
$("table tr:last, obj").append("<td id = '"+formatdate+"'>"+i+"</td"); //add day
}
else
{
options.beforeDay(formatdate);
$("table tr:last, obj").append("<td class='date_has_event' id = '"+formatdate+"' name='"+formatdate+"'>"+i+"<div class='title'><a href='#' class='popup'><img src='images/facebook.png' class='popup'/></a></div>"+"<div class='events'><ul><li><span class='desc'>"+datejson.desc+"</span></li></ul></div></td"); //add day
}
HTML中的PHP:
<div id="popupContact">
<a href="#" id="popupContactClose">Close X</a>
<div id="popupHeader">Events occurring on</div>
<?php
include ("Includes/dbConnect.php");
$calendarDate=$_GET['formatdate']
$query = "SELECT * FROM events WHERE eventDate='$calendarDate'";
$check = mysqli_query($cxn,$query) or die("Couldn't execute query!");
while($row = mysqli_fetch_array($check))
{
$id = $row['eventID'];
echo "<div class='submit_event_list'><a href='individual_event_page_main.php?id=$id'>";
echo $row['eventName'];
echo " | " . $row['venue'];
echo " | " . $row['eventDate'];
echo "</a></div>";
echo "<br />";
}
mysqli_close($cxn);
?>
</div>