Uncaught ReferenceError: $ is not defined when <td> is defined
Uncaught ReferenceError: $ is not defined when <td> is defined
背景
我正在制作 4 个日历:
- 当前日历
- 下个月的日历
- 上个月的日历
- 从现在开始的2个月日历//
$dateInt = date("U", strtotime("+2 months"));
我的日历构建得很好,包括从我的 SQL Database Table
动态加载值(以后我将称之为 DB
)。自 90 年代后期以来,我一直在断断续续地做 PHP
,但出于某种原因,我忘记了 class
的概念,所以我切换了加载日历的“functions.php”页面并添加了 class
和 __constructor
。
日历仍然构建得很好,但是从数据库动态加载和添加值已经停止,现在抛出 Uncaught ReferenceError: $ is not defined at calendar.php:466:29
错误。我根本没有移动代码的 JQuery
部分(除了它现在位于 class
而不是 function
...
代码
<?php
$currentCal = new Calendar("Current");
$nextCal = new Calendar("Next");
$priorCal = new Calendar("Prior");
$wipCal = new Calendar("WIP"); //2 Month's from $currentCal
if (isset($_POST['cal'])) {
new Calendar($_POST['cal']);
unset($_POST);
}
class Calendar
{
function __construct($cat)
{
include "assets/system/connect.php";
try {
//A LOT OF REDACTED SCRIPT FOR BUILDING THE CALENDAR BUT HERE'S THE FORMATTING FOR THE IDs ON THE FIELDS
echo " <tr class='content'>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 7 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 6 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 5 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 4 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 3 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 2 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 1 . "NonFlight'></td>
</tr><tr class='content'>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 7 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 6 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 5 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 4 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 3 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 2 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 1 . "Flight'></td>
</tr>";
//MORE REDACTION
} catch (RuntimeException $e) {
echo "<script>console.log('Error: $e')</script>";
}
/** POPULATING THE CALENDAR **/ //THE ISSUE APPEARS TO BE IN THIS SECTION
$startTime = 0; //TEMP VALUE
$endTime = 999999999999999999; //TEMP VALUE
try {
$conn = new PDO("mysql:host=$servername;dbname=bcor", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->query("SELECT * FROM resss WHERE `startDate` > '$startTime' AND `endDate` <= '$endTime'")->fetchAll();
foreach ($stmt as $row) {
extract($row, EXTR_OVERWRITE);
$startDay = date('d', $row['startDate']);
switch ($location) {
case (/**REDACTED**/):
$region = "Central";
$travel = "NonFlight";
break;
//REDACTED SUPURFLOUS INFO
}
$tdID = $region . $cat . $startDay . $travel;
if ($staff != null && $staff != "") {
$display = "<span class=location>$location</span><br/><span class=content>$department: $provider/$staff</span>";
} else {
$display = "<span class=location>$location</span><br/><span class=content>$department: $provider</span>";
}
echo "<script>$('#$tdID').html('$display');</script>"; //THIS IS WHERE THE ERROR IS FLAGGED
//VALUE ON FIRST RUNTHROUGH IS:
//$('#CentralCurrent11NonFlight').html('<span class=location>Big Timber</span><br/><span class=content>Cardio: Who/Staff</span>');</script>
//REDACTING REMAINDER
抱歉,篇幅太长了 - 我试图删除所有我认为不是绝对必要的内容。如果需要,我可以提供完整的代码,只需给我发送到的地方 - 它超过 100 行。
我检查了 Chrome 中的 Dev Console 和 Sources 部分,确实发现 CentralCurrent11NonFlight
确实存在:
<tr class='content'>
<td class='nonFlight' id='CentralCurrent8NonFlight'></td>
<td class='nonFlight' id='CentralCurrent9NonFlight'></td>
<td class='nonFlight' id='CentralCurrent10NonFlight'></td>
<td class='nonFlight' id='CentralCurrent11NonFlight'></td> //WINNER WINNER
<td class='nonFlight' id='CentralCurrent12NonFlight'></td>
<td class='nonFlight' id='CentralCurrent13NonFlight'></td>
<td class='nonFlight' id='CentralCurrent14NonFlight'></td>
</tr>
最初我认为问题是第一个 $
作为变量被回显,所以我添加了 \
字符来删除它:
echo "<script>$('#$tdID').html('$display');</script>";
它没有解决问题,但我将保留它,因为它看起来更……合适……在 echo
.
范围内
任何想法都会有所帮助。
谢谢!
这是一个 DOM
问题 - 在我最顶部的 calendar.php
页面上,我有:
<?php
include "assets/system/functions.php";
$currentCal = new Calendar("Current");
$nextCal = new Calendar("Next");
$priorCal = new Calendar("Prior");
$wipCal = new Calendar("WIP");
?>
远远早于任何 DOM
创建。
我把它移到了页面底部,效果非常好。
背景 我正在制作 4 个日历:
- 当前日历
- 下个月的日历
- 上个月的日历
- 从现在开始的2个月日历//
$dateInt = date("U", strtotime("+2 months"));
我的日历构建得很好,包括从我的 SQL Database Table
动态加载值(以后我将称之为 DB
)。自 90 年代后期以来,我一直在断断续续地做 PHP
,但出于某种原因,我忘记了 class
的概念,所以我切换了加载日历的“functions.php”页面并添加了 class
和 __constructor
。
日历仍然构建得很好,但是从数据库动态加载和添加值已经停止,现在抛出 Uncaught ReferenceError: $ is not defined at calendar.php:466:29
错误。我根本没有移动代码的 JQuery
部分(除了它现在位于 class
而不是 function
...
代码
<?php
$currentCal = new Calendar("Current");
$nextCal = new Calendar("Next");
$priorCal = new Calendar("Prior");
$wipCal = new Calendar("WIP"); //2 Month's from $currentCal
if (isset($_POST['cal'])) {
new Calendar($_POST['cal']);
unset($_POST);
}
class Calendar
{
function __construct($cat)
{
include "assets/system/connect.php";
try {
//A LOT OF REDACTED SCRIPT FOR BUILDING THE CALENDAR BUT HERE'S THE FORMATTING FOR THE IDs ON THE FIELDS
echo " <tr class='content'>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 7 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 6 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 5 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 4 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 3 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 2 . "NonFlight'></td>
<td class='nonFlight' id='" . $regions[$calendars] . $cat . $date - 1 . "NonFlight'></td>
</tr><tr class='content'>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 7 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 6 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 5 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 4 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 3 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 2 . "Flight'></td>
<td class='flight' id='" . $regions[$calendars] . $cat . $date - 1 . "Flight'></td>
</tr>";
//MORE REDACTION
} catch (RuntimeException $e) {
echo "<script>console.log('Error: $e')</script>";
}
/** POPULATING THE CALENDAR **/ //THE ISSUE APPEARS TO BE IN THIS SECTION
$startTime = 0; //TEMP VALUE
$endTime = 999999999999999999; //TEMP VALUE
try {
$conn = new PDO("mysql:host=$servername;dbname=bcor", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->query("SELECT * FROM resss WHERE `startDate` > '$startTime' AND `endDate` <= '$endTime'")->fetchAll();
foreach ($stmt as $row) {
extract($row, EXTR_OVERWRITE);
$startDay = date('d', $row['startDate']);
switch ($location) {
case (/**REDACTED**/):
$region = "Central";
$travel = "NonFlight";
break;
//REDACTED SUPURFLOUS INFO
}
$tdID = $region . $cat . $startDay . $travel;
if ($staff != null && $staff != "") {
$display = "<span class=location>$location</span><br/><span class=content>$department: $provider/$staff</span>";
} else {
$display = "<span class=location>$location</span><br/><span class=content>$department: $provider</span>";
}
echo "<script>$('#$tdID').html('$display');</script>"; //THIS IS WHERE THE ERROR IS FLAGGED
//VALUE ON FIRST RUNTHROUGH IS:
//$('#CentralCurrent11NonFlight').html('<span class=location>Big Timber</span><br/><span class=content>Cardio: Who/Staff</span>');</script>
//REDACTING REMAINDER
抱歉,篇幅太长了 - 我试图删除所有我认为不是绝对必要的内容。如果需要,我可以提供完整的代码,只需给我发送到的地方 - 它超过 100 行。
我检查了 Chrome 中的 Dev Console 和 Sources 部分,确实发现 CentralCurrent11NonFlight
确实存在:
<tr class='content'>
<td class='nonFlight' id='CentralCurrent8NonFlight'></td>
<td class='nonFlight' id='CentralCurrent9NonFlight'></td>
<td class='nonFlight' id='CentralCurrent10NonFlight'></td>
<td class='nonFlight' id='CentralCurrent11NonFlight'></td> //WINNER WINNER
<td class='nonFlight' id='CentralCurrent12NonFlight'></td>
<td class='nonFlight' id='CentralCurrent13NonFlight'></td>
<td class='nonFlight' id='CentralCurrent14NonFlight'></td>
</tr>
最初我认为问题是第一个 $
作为变量被回显,所以我添加了 \
字符来删除它:
echo "<script>$('#$tdID').html('$display');</script>";
它没有解决问题,但我将保留它,因为它看起来更……合适……在 echo
.
任何想法都会有所帮助。
谢谢!
这是一个 DOM
问题 - 在我最顶部的 calendar.php
页面上,我有:
<?php
include "assets/system/functions.php";
$currentCal = new Calendar("Current");
$nextCal = new Calendar("Next");
$priorCal = new Calendar("Prior");
$wipCal = new Calendar("WIP");
?>
远远早于任何 DOM
创建。
我把它移到了页面底部,效果非常好。