Amazon suggest
HTML
<script src="http://ivaynberg.github.com/select2/select2-3.1/select2.js"></script>
<link rel="stylesheet" href="http://ivaynberg.github.com/select2/select2-3.1/select2.css">
<input type="text" id="query" />
YO SE QUE SIII
<H1>
<CENTER> SECLLA </CENTER>
</H1>
<H3>
<CENTER> MEJOR QUE MARTE</CENTER>
</H3>
</BR>
</P>
<H3>
<CENTER> POR FAVOR CASTILLO DEJA DE JALARTELA </CENTER>
</H3>
</BR>
<CENTER>XAVI CONTINUA CON TU VISA NET POR FAVOR </CENTER>
</H3>
JavaScript
$("#query").select2({
placeholder: "Search for a product",
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "http://completion.amazon.com/search/complete",
dataType: 'jsonp',
data: function (term, page) {
return {
q: term, // search term
"search-alias": "videogames",
mkt: "1",
callback: '?'
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
var val = { results: [] };
var res = data[1];
console.log(res);
for (i = 0; i < res.length; i++) {
val.results.push({
id: res[i],
text: res[i],
});
console.log(val);
}
// since we are using custom formatting functions we do not need to alter remote JSON data
return val;
}
}
});