4

I'm having trouble with jQuery and Mozzila Firefox. Everything is working just fine in Chrome, but somehow Firefox does not see jQuery.

This is how I call jQuery

 <!-- Favicon and touch icons -->
    <link rel="shortcut icon" href="assets/ico/favicon.png">


    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script type="text/javascript" src="assets/bootstrap/js/datepicker.js"></script>

And this is where it fails (error is: ReferenceError: $ is not defined):

 <script>
        function ajax_check(){

            var id = $("#xml_select").val(); // this is the line where I get error

             $.ajax({
                    url: "ajax_check.php?id="+id,
                    success: function(response) {

                        var result = jQuery.parseJSON(response);

                       //console.log( JSON.stringify(result['ncp'].replace('"','')) );

                       var ncp = JSON.stringify(result['ncp']);
                       var id = JSON.stringify(result['id']);


                       $("#racun").val(ncp.substring(1,12));

                       $("#id_podnosilac").val(id.substring(1,5));
                    }, 
                  });

        }
</script>

Please help, what could be causing this?

dj.milojevic
  • 134
  • 1
  • 2
  • 11

5 Answers5

6

You will get this error randomly based on loading time/different browsers. Because Root cause of this is that you are loading jquery.min.js from googleapis. Third party domain resources will get low priority than the local domain resources. "document ready" function statements will be triggered once the local domain resources are loaded. That is why you get this error.

Permanent Solution: Put jquery.min.js file in your server and call it from your domain. this solution will work even if your page has load time issues and in any browser.

Thanga
  • 6,775
  • 3
  • 14
  • 34
  • This will not always fix the issue. In my case, I already loaded jQuery from my server, but I included jQuery and my JS at the end of the DOM, which resulted in the same error. Putting it in the helped a little bit, but it still fails ~10% of the time. – Spomsoree Jan 19 '21 at 15:55
  • Followup: Including jQuery at multiple places seem to confuse firefox. This eliminated the last 10% for me. – Spomsoree Jan 19 '21 at 16:07
1

Solution found by A.Wolf

Firefox started to work fine when i made couple of full requests(ctrl+f5) as A.Wolf suggested.

Community
  • 1
  • 1
dj.milojevic
  • 134
  • 1
  • 2
  • 11
  • 4
    As a developer, We cannot expect the users of the website, to press ctrl+f5. Most of the users does not know this. We should give permanent solutions. – Thanga Oct 19 '16 at 08:06
1

use "jQuery" word (with out qutation) instead of $ in your code

Omid Ahmadyani
  • 1,012
  • 9
  • 13
1

This problem persists even 3 years later. some people use jquery just for the $ function which is ridiculous. One could program it oneself.

$ = document.getElementById or ByClass there are many ways to search within the DOM and new ones that are appearing.

I had the problem of assigning functions for when the document was loaded which was solved by this question here

lesolorzanov
  • 3,147
  • 6
  • 31
  • 48
-1

as suggested by A.Wolf. You need to press 'ctrl+f5' key. Sometimes it happens due to cache. Use 'ctrl+shift+delete' and clean the browser cache then run your code.

Community
  • 1
  • 1
Kannu
  • 11
  • 3