I'm trying to build an autocomplete form which will load JSON from an external database (which returns JSON) on user input. My code seems to work properly as it will log an array containing multiple JSON objects. However, jQuery UI does not show the results on the page itself.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tables</title>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>
<body>
<div class="ui-widget">
<input type="text" id="tags" />
</div>
<script src="assets/js/script.js"></script>
</body>
</html>
JS
$(document).ready(function(){
function createUrl(input){
var url = "http://forums.zybez.net/runescape-2007-prices/api/" + input;
return url;
}
function getSource(input){
var input = input.term;
var url = createUrl(input);
$.getJSON(url, function(data){
var items = [];
$.each( data, function(key, val){
items.push(val);
});
console.log(items); // Shows correct results
return items;
});
}
$("#tags").autocomplete({
minLength: 2,
source: getSource
});
});
What can be the problem? Thanks in regards.