I'm trying to get auto-complete working with a simple application that I'm building. Here is my code so far:
gMeds = new Array();
$(document).ready(function(){
var autoComp = setUpAutoComplete();
if(autoComp) {
$("#med").autocomplete(gMeds);
}
else {
alert('Autocomplete unavailable');
}
});
function setUpAutoComplete() {
$.ajax({
url: "ajax-getAllMeds.php",
async: false,
type: "GET",
dataType: "text",
success: function(result){
gMeds = JSON.parse(result);
return true;
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
return false;
}
});
}
The source of "ajax-getAllMeds.php" produces valid JSON (as verified by http://www.jsonlint.com/).
The JSON produced is
{
"meds": [
{
"name": "ace"
},
{
"name": "danger"
}
]
}
What I'm trying to accomplish is turning my JSON into a javascript array and then using that array as the basis for my pool of words to "autocomplete from". Am I way off? I'm running into various problems.