I have no idea why the result array is empty after a successful ajax call. I am definitely getting the data back from the source url which is added to the array but the result is empty in return result statement.
Thanks for your help.
function locationSearch(loc) {
var result = [];
$.ajax({
data: 'q=description:' + loc + '*&wt=json&json.wrf=?&fl=*',
url: 'http://deviis:8080/Locations/select/',
aSync: false,
success: function (data) {
result.push({ value: "Any", data: "*" });
$.each(data.response.docs, function (i, item) {
result.push({ value: item.description, data: item.id });
});
}
});
return result;
}
You may want to try doing the return job inside the success callback. Always be aware of the closures in javascript programming.
John resig’s answer to this post should help.