The task is to get local JSON file with array of city names and put them to autocomplete. There is no info exactly about JSON arrays, always talk about pairs 'key'-'value'. So I have a question: is it possible to use arrays with single items in JSON and if it is where is the mistake of my code?
JSON
[
"Minsk",
"London",
"Riga",
"Vilnius",
"Warszaw",
"Paris",
"Moscow",
"Tallin",
"Berlin",
"Amsterdam",
"Oslo",
"Helsinki"
]
JS
$('#tags').autocomplete({
source: function(request, response) {
var result = $.ajax({
url: '../source.json',
method: 'GET',
dataType: 'json',
success: function(data) {
var array = [];
response($.each( data, function(item) {
array.push(item);
return array;
}));
return array;
}
});
}
});
source.jsonfile. If this works, make../source.jsonan absolute path and see if your AJAX call will work. In your success function I would put in aconsole.log(data)statement so you can see what is being returned from the URL.file://), this is unlikely to work. As soon as you move beyond basic development, you usually need to serve files as though they came from a webserver