0

I am using JQuery autocomplete in my application using this code:

$(document).ready(function(){
    var data = [{"value":"one"},{"value":"two"}];
    $("#company").autocomplete({
        source:data,
        select: function(e, ui) {
            e.preventDefault() // <--- Prevent the value from being inserted.
            $(this).val(ui.item.value);
        }
    });
});

I have a text input with an id of company

I am using jQuery-2.1.3.min.js stored locally on my server

When I type into the text input, nothing is displaying. In the console, I can see an error on the line:

$(document).ready(function(){

the error is saying:

Uncaught ReferenceError: $ is not defined

What could be causing this issue? I have also tried including jQuery version 1.10.2 and this made no difference

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
charlie
  • 415
  • 4
  • 35
  • 83
  • possible duplicate of [Uncaught ReferenceError: $ is not defined?](http://stackoverflow.com/questions/2075337/uncaught-referenceerror-is-not-defined) – User404 Apr 28 '15 at 12:44
  • Link jquery first, and then only then, link the others js codes –  Apr 28 '15 at 12:45

1 Answers1

0

Please include jQuery first :

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

And then your other scripts (JS) :

<script src=".."> </script>
Jules
  • 295
  • 1
  • 10
  • Can you try a put those 2 links (from `jQuery`) at the beginning of your code (that you just linked). – Jules Apr 28 '15 at 12:56
  • Those ones : `` and `` – Jules Apr 28 '15 at 12:59
  • ok i put them right up the top and still get the same reference error – charlie Apr 28 '15 at 13:00
  • Can you please check your console and tell me if all your JS files are being loaded correctly? – Jules Apr 28 '15 at 13:04
  • they are - its just that one reference error in the console now – charlie Apr 28 '15 at 13:05
  • Can you please make a JSFiddle with only the essential things (We've checked most of the things that could make that error happened). – Jules Apr 28 '15 at 13:11
  • My bad, you have to include the jQueryUI file ( it's from there that you get the function autocomplete) : `https://code.jquery.com/ui/1.11.4/jquery-ui.js`. Also, please change your array formatting and go for a thing like that : `var data = ["one", "two", "three"];` – Jules Apr 28 '15 at 13:22
  • in what order should i include them ? – charlie Apr 28 '15 at 13:23
  • Both `jQuery` in no particular order, just before your other JS files (you could go `jQuery` -> `jQueryUI` -> other JS files – Jules Apr 28 '15 at 13:24
  • so i have included these: ` ` but its still not working – charlie Apr 28 '15 at 13:26
  • Please change the `//` to `https://`, those files aren't on your computer (the UI one at least). Pastebin : http://pastebin.com/Wd13vZmx – Jules Apr 28 '15 at 13:27
  • Check pastebin please and download firebug, you should have had a `404 Error` when adding the files I gave you (that I forgot to mention that you had to change the `//`). – Jules Apr 28 '15 at 13:34