JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/black-tie/jquery-ui.css">
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.min.js"></script>
<input id="airport" />
JavaScript
function buildQuery(term) {
return "select * from json where url = 'http://airportcode.riobard.com/search?fmt=JSON&q=" + encodeURI(term) + "'";
}
function makeRequest(request, response) {
$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql',
data: {
q: buildQuery(request.term),
format: "json"
},
dataType: "jsonp",
success: function(data) {
var airports = [];
if (data && data.query && data.query.results && data.query.results.json && data.query.results.json.json) {
airports = data.query.results.json.json;
}
response($.map(airports, function(item) {
return {
label: item.code + (item.name ? ", " + item.location : "") + ", " + item.location,
value: item.code
};
}));
},
error: function () {
response([]);
}
});
}
$(document).ready(function() {
$("#airport").autocomplete({
source: makeRequest,
minLength: 2
});
});