-3

Getting this error, I have included the latest jquery file. Also, I have added this file in head section while I am calling jquery function in the body. Can't figure out what the problem is?

Here is my code to include jquery:

<script type="text/javascript" src="<?php echo base_url(); ?>assets/admin/js/vendor/jquery-3.3.1.min.js"></script>

and jquery call is:

$(document).ready(function() {
  $("#submit").on("click", function (e) {
    alert('test');
  });
});

Error is: enter image description here

9
  • 3
    No code, no help possible.
    – Geshode
    Jul 9, 2018 at 7:29
  • Questions seeking debugging help should include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it within the question itself. Questions without a clear problem statement are not useful to other readers. Please see: How to create a Minimal, Complete, and Verifiable example. Jul 9, 2018 at 7:33
  • 1
    Also note if the $ in the error message is referring to jQuery then this has absolutely nothing to do with CodeIgniter or PHP Jul 9, 2018 at 7:33
  • Thank you for editing the code in to the question. The problem is simply because the path to the jquery.js file you're using is wrong. You need to fix it. We can't tell you how, as we don't know your folder structure. Jul 9, 2018 at 7:34
  • What is the result of <?php echo base_url(); ?>assets/admin/js/vendor/jquery-3.3.1.min.js? Maybe the jQuery file cannot be loaded.
    – dns_nx
    Jul 9, 2018 at 7:35

1 Answer 1

4

var $ = jQuery;

try this on top

//edit

try this:

(function($) {
    $(document).ready(function() {
        $("#submit").on("click", function (e) {
            alert('test');
        });
    });
})(jQuery);
7
  • no this could also mean, jquery is in compatibility mode and does not register $ - but you are right.. i edit..
    – Kapsonfire
    Jul 9, 2018 at 7:37
  • That's not working .... Same error Jul 9, 2018 at 7:37
  • are you sure, jQuery is loaded? check the var jQuery
    – Kapsonfire
    Jul 9, 2018 at 7:39
  • I have changed my code with one you provided. Now error is: Uncaught TypeError: document.ready is not a function Jul 9, 2018 at 7:41
  • seems like you are missing the $ before (document)
    – Kapsonfire
    Jul 9, 2018 at 7:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.