[Special Summer Sale] 40% OFF All Magento 2 Themes

Cart

JQuery – $ is not defined

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #9717
    sc123
    Participant

    it appears that if you locate your jquery.js files under the same folder or in some subfolders where your html file is, the Firebug problem is solved. eg if your html is under C:/folder1/, then your js files should be somewhere under C:/folder1/ (or C:/folder1/folder2 etc) as well and addressed accordingly in the html doc. hope this helps.

    #9711
    asifaftab87
    Participant

    u just add at starting of your page

     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    

    and check your src link in a any browser address bar, if you are getting some code then this will work for you.
    asif

    #9718
    amelian
    Participant

    I have the same issue and no case resolve me the problem. The only thing that works for me, it’s put on the of the Site.master file, the next:

    <script src="<%= ResolveUrl("~/Scripts/jquery-1.7.1.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/Scripts/bootstrap/js/bootstrap.min.js") %>" type="text/javascript"></script>
    

    With src=”<%= ResolveUrl(“”)… the load of jQuery in the Content Pages is correct.

    #9728
    develop4life
    Participant
    1. Check the exact path of your jquery file is included.

      <script src="assets/plugins/jquery/jquery.min.js"></script>

    if you add this on bottom of your page , please all call JS function below this declaration.

    1. Check using this code test ,

      <script type="text/javascript">
      /***
       * Created by dadenew
       * Submit email subscription using ajax
       * Send email address
       * Send controller
       * Recive response
       */
      $(document).ready(function() { //you can replace $ with Jquery
      
        alert( 'jquery working~!' );
      });
      

    Peace!

    #9719
    bhow
    Participant

    I had a very similar issue. In my C# MVC application, JQuery was not being recognized. I needed to move the @Scripts.Render(“~/bundles/jquery”) from the bottom of my _Layout.cshtml file to the head of the section. Also make sure you have grabbed Jquery as a Nuget package if you are using visual studio!

    <head>
        @Scripts.Render("~/bundles/jquery")
    </head>
    
    #9740
    naveed-abbas
    Participant

    As stated above, it happens due to the conflict of $ variable.

    I resolved this issue by reserving a secondary variable for jQuery with no conflict.

    var $j = jQuery.noConflict();
    

    and then use it anywhere

    $j( "div" ).hide();
    

    more details can be found here

    #9720
    pat
    Participant

    There is a way to make it automatically load up javascript before the rest of the code runs.

    Go into Views\Shared_Layout.html and add the following

    <head>
      <*@ Omitted code*@>
      <script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
    </head>
    
    #9739
    wolfgang-fahl
    Participant

    make sure you really load jquery
    this is not jquery – it’s the ui!

      <script language="JavaScript" 
        src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js">
      </script>
    

    This is a correct script source for jquery:

     <script language="JavaScript"  src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
    
    #9733
    kyle-mcvay
    Participant

    That error means that jQuery has not yet loaded on the page. Using $(document).ready(...) or any variant thereof will do no good, as $ is the jQuery function.

    Using window.onload should work here. Note that only one function can be assigned to window.onload. To avoid losing the original onload logic, you can decorate the original function like so:

    originalOnload = window.onload;
    window.onload = function() {
      if (originalOnload) {
        originalOnload();
      }
      // YOUR JQUERY
    };
    

    This will execute the function that was originally assigned to window.onload, and then will execute // YOUR JQUERY.

    See https://en.wikipedia.org/wiki/Decorator_pattern for more detail about the decorator pattern.

    #9721
    abdulahmad-matin
    Participant

    if script tag has defer attribute it show the error

    Uncaught ReferenceError: $ is not defined

    and must remove the attribute defer from script tag

    #9729
    anju-batta
    Participant

    This is the common issue to resolve this you have to check some point

    1. Include Main Jquery Library
    2. Check Cross-Browser Issue
    3. Add Library on TOP of the jquery code
    4. Check CDNs might be blocked.

    Full details are given in this blog click here

    #9722
    david-van-driessche
    Participant

    Something that I didn’t find here, but did happen to me. Make sure you don’t have the jQuery slim version included, as that version of the jQuery library doesn’t include the Ajax functionality.

    The result is that “$” works, but $.get for example returns an error message stating that that function is undefined.

    Solution: include the full version of jQuery instead.

    #9736
    walmac
    Participant

    I had the same problem and resolved it by using

    document.addEventListener('DOMContentLoaded', () => {
     // code here
    });
    
    #9730
    adityaubale
    Participant

    I came across same issue, and it resolved by below steps.
    The sequence of the scripts should be as per mentioned below

        <script src="~/Scripts/jquery-3.3.1.min.js"></script>
        <script src="~/Scripts/jquery-ui.js"></script>
        <script src="~/Scripts/bootstrap.min.js"></script>
    

    This sequence was not correct for my code, I corrected this as per the above and it resolved my issue of Jquery not defined.

    #9723
    dwain-b
    Participant

    I was having the same issue and now I have it resolved. My environment is as below;

    Laravel with Blade Pages. I had a main layout and used sections to create new pages form my main page layout(template).

    I was loading JQuery from my section page and not my main layout. I changed it from the section page to load JQuery from the main layout and also at the top in the head tag.

Viewing 15 posts - 16 through 30 (of 31 total)
  • You must be logged in to reply to this topic.