Skip to main content

Uncaught ReferenceError: $ is not defined when is defined

Background I'm making 4 calendars:

  • The Current Calendar
  • Next Month's Calendar
  • Last Month's Calendar
  • 2 Month's From now Calendar //$dateInt = date("U", strtotime("+2 months"));

I had the calendars building just fine, including the dynamic loading of values from my SQL Database Table (I'll just call it DB henceforth) . I have been doing PHP off and on since the late 90s but for whatever reason, I'd forgot the concept of class, so I switched my "functions.php" page where the calendar loads and added the class and __constructor instead.

The calendars still build just fine, but the dynamic loading and adding of the values from DB has stopped and is now throwing the Uncaught ReferenceError: $ is not defined at calendar.php:466:29 error. I did not move the JQuery portion of the code at all (other than it's inside a class now instead of a function...

The Code

<?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

I'm sorry the for the length - I tried to take out everything I didn't think was absolutely necessary. I can provide the full code if desired, just give me somewhere to send it to - it's over 100 lines.

I did check the Dev Console and Sources sections in Chrome and did find that CentralCurrent11NonFlight does exist:

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

Originally I thought the problem was that the first $ was being echo'd as a variable, so I added the \ character to remove that: echo "<script>\$('#$tdID').html('$display');</script>"; It didn't fix the problem, but I'm going to leave it as it seems more... appropriate... within the echo.

Any thoughts would be helpful.

Thank you!

Via Active questions tagged javascript - Stack Overflow https://ift.tt/9fnX31D

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data