2

I'm trying to get the jquery autocomplete ui to work but without success. There is no list of matches presented. I'm getting the error "TypeError: this.source is not a function"

so far I have an input field <input type="text" id="searchbar" name="title" placeholder="Search">

and then in my script I have

I'm not getting this to work. anyone have any ideas of where I can begin to troubleshoot? I really have a hard time with the jquery ui documentation.

1
  • change source: "data", to source: data, Commented Apr 29, 2017 at 11:56

2 Answers 2

0

You only have to use this code for your autocomplete:

$("#searchbar").autocomplete({
    source: "php/searchbar.php",
    minLength: 3
});

You don't have to do an extra ajax request. The plugin it self does the ajax request.

You have an missing hash in your autocomplete selector too:
$("searchbar") vs. $("#searchbar")

I have created a jsfiddle here: https://jsfiddle.net/9rtu412g/

Source from documentation here: https://jqueryui.com/autocomplete/#remote (view source)

For your jQuery version:
<script src="js/jquery-1.6.js" type="text/javascript"></script>

Use this jQuery UI version: https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js

I hope I could help you to solve your problem.

Sign up to request clarification or add additional context in comments.

6 Comments

With this, in my html <script></script> instead of a seperate JS file, I get the error "TypeError: $(...).on is not a function"
TypeError: $(...).on is not a function - <script src="js/jquery-1.6.js" type="text/javascript"></script>
@Polarbearz Updated. I hope you are using jQuery UI 1.11.4 (Legacy, for jQuery1.6+) or lower for autocomplete?
Using the code you have given it is now working without errors, and displaying the results like this: puu.sh/vzYwk/806628ecd5.png . I am greatful for your help, I just need to display the results in a better way somehow now. For some reason I also can't click on the result and be linked to the page/event.
@Polarbearz have you added the CSS file from the jQuery UI package to your page? Like this: cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/…
|
0

At first console.log your data to check is there any data returned from ajax request then remove double quote from your data variable.

 source: "data"(wrong)
 source: data(right)

wish it helps

1 Comment

I changed this, and now I am getting the error: TypeError: this.source is not a function - according to this thread, stackoverflow.com/questions/3308935/…, the data needs to be put inside a variable, and I've updated my JS above, whilst still getting the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.