Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8913679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:31:24+00:00 2026-06-15T04:31:24+00:00

I’m building a CMS with PHP/MySQL, and so far using jQuery to add sorting

  • 0

I’m building a CMS with PHP/MySQL, and so far using jQuery to add sorting and filtering to table columns. Usually, it works great, but occasionally the sorting and filtering elements won’t load – this only happens if I manually refresh the page (never if I access it through a link), and only sometimes. There are times when I can refresh several times before it happens, where other times it can happen several times in a row.

When the issue occurs, Firebug’s Console tells me one or both of the following:

ReferenceError: jQuery is not defined

ReferenceError: $ is not defined
$(document).ready(function(){

(and sometimes: TypeError: $(“.tablesorter”).tablesorter is not a function)

When everything loads fine, the Console is blank.

My header file, which loads on all pages of the CMS, starts with:

<?php ob_start(); ?>
<!DOCTYPE html>
<html>
<head>
    <meta name="robots" content="noindex">
    <title><?=$pg_title." - ".$site_name;?> | Lucid <?=$ver_num;?></title>
    <link href="/favicon.gif" rel="icon" />
    <link rel="stylesheet" href="css/styles.php" type="text/css" />
    <script src="js/jquery-1.8.3.min.js" async></script>
    <script src="plugins/jquery-tablesorter/js/jquery.tablesorter.min.js" async></script>
    <script src="plugins/jquery-tablesorter/js/jquery.metadata.js" async></script>
    <script src="plugins/jquery-tablesorter/addons/pager/jquery.tablesorter.pager.min.js" async></script>
    <script src="js/picnet.table.filter.min.js" async></script>
</head>

Then in the footer file, I call various functions:

 <script async>
    $(document).ready(function(){
        function validateNumber(event) {
            var key = window.event ? event.keyCode : event.which;

            if (event.keyCode == 8 || event.keyCode == 46
             || event.keyCode == 37 || event.keyCode == 39) {
                return true;
            }
            else if ( key < 48 || key > 57 ) {
                return false;
            }
            else return true;
        };
        $('[class=sort-order]').keypress(validateNumber);
        $(".tablesorter").tablesorter({ 
            textExtraction: 'complex'
        }); 
        var options = {
            filterDelay: 100,
            clearFiltersControls: [$('.filter-clear')]
        };
        $('.tablesorter').tableFilter(options);
        $('input:not(.filter)').live("change", function () {
            window.onbeforeunload = function () { return "Your changes have not been saved, if you leave the page you'll lose them" };
        });
    });
</script>
</body>
</html>
<?php 
ob_flush();
?>

I’m aware that this is a fairly common problem, but I feel I’ve tried all the solutions (including those listed here: JQuery – $ is not defined)

I’ve tried using setTimeout to delay the loading of all scripts other than jQuery for up to one second – doesn’t help.

I’ve tried checking whether jQuery is defined with if(jQuery) – it always is.

Firebug’s Net tab shows me that the jQuery file has the status 304 Not Modified, regardless of whether the issue has occurred.

As far as I can tell all my spelling and syntax is fine, which it should be given that it does work most of the time.

I’ve tried loading jQuery from an external website instead of locally – no difference.

I should point out that I’m using XAMPP to develop the CMS locally, rather than a remote server, so I thought it might be something amiss with my apache config. I then uploaded everything to a remote server and found the problem was worse, which suggests it’s something to do with the speed of loading the page, maybe the async? But I don’t know what else I can do to make sure jQuery loads before loading any scripts…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:31:26+00:00Added an answer on June 15, 2026 at 4:31 am

    The async attribute on script elements means that the parsing of the HTML may continue before the script is downloaded and evaluated. Which means that subsequent script elements cannot rely on previous ones having been evaluated — which means that the jQuery plug-ins you’re loading after jQuery fail, because jQuery isn’t loaded yet.

    Specifically:

    <script src="js/jquery-1.8.3.min.js" async></script>
    

    tells the browser you want that script, but not to hold things up waiting for it. Then:

    <script src="plugins/jquery-tablesorter/js/jquery.tablesorter.min.js" async></script>
    

    says the same thing. This sets up a race condition, there is no longer any order to those two script elements, and so sometimes the second one gets evaluated first. Since the second one requires jQuery, that fails.

    To fix it, you need to remove the async attribute. If your goal is for the page to render more quickly, without waiting for scripts, move all of your scripts to the end of the body (e.g., just before </body>). But note that that can mean a brief moment when the user tries to interact with the page before event handlers are hooked up and such.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.