Im trying to get some auto complete to work. I have this URL i shoud read my JSON From:
http://openscan.addi.dk/2.0/?action=openScan&field=phrase.title&lower=hest&limit=10&outputType=json
When i receive the result i try to map it into my jquery autocomplete, i use the following jquery:
<script type="text/javascript">
$(function () {
function log(message) {
$("<div/>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#search").autocomplete({
source: function (request, response) {
$.ajax({
url: "http://openscan.addi.dk/2.0/?action=openScan&field=phrase.title&lower=hest&limit=10&outputType=json",
dataType: "jsonp",
success: function (data) {
response($.map(data.scanResponse.term, function (item) {
return {
label: item.name+' ( '+item.hitCount+')',
value: item.name
}
}));
}
});
},
minLength: 2,
select: function (event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function () {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function () {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
</script>
<h2>
Demo of autocomplete using OpenScan
</h2>
Start typing below.<br />
<input id="search" />
My problem is the result its not like the limited amount of JSON i have seen before, it contains $ and @ for properties, how do I index them?
Edit
Changed data.scanResponse to data.scanResponse.term
Not sure what are exact values you want to display, but you could access properties using array syntax, like this: