I try to get an instant search with jquery ui autocomplete, I want to add link onclick result.
JScript
$("#searchinput").autocomplete({
source: "search/get_searchdata",
select:function(e,ui) {
location.href = ui.item.the_link;
};
});
HTML
<div class="ui-widget">
<input id="searchinput">
</div>
The script work and show me results from array:
Array
[
{
"label": "Apple annuncia OS X El Capitan",
"the_link": "../../../post/2"
},
{
"label": "Apple l'Phone flessibile",
"the_link": "../../../post/5325"
},
{
"label": "iCloud Apple, attacco hacker in Cina",
"the_link": "../../../post/5637"
}
]
/* Lint by jsonlint.com */
But when i click a result the page not change.
Note: I use jQuery 1.9.1 version.
Is that what you looking for?
Code working Html <div class="ui-widget"> <input id="searchinput"/> </div>
JavaScript
var jsonData = [ {
"label": "Apple annuncia OS X El Capitan",
"the_link": "http://www.apple.com"
},{
"label": "Apple l'Phone flessibile",
"the_link": "http://www.apple.com/iphone"
},{
"label": "iCloud Apple, attacco hacker in Cina",
"the_link": "http://www.icloud.com"
}];
$("#searchinput").autocomplete({
source: jsonData,
select: function(event,ui) {
window.location.href = ui.item.the_link;
}
});
It is a syntax error, when objects are assigned, they should not have semicolons:
$("#searchinput").autocomplete({
source: "search/get_searchdata",
select:function(e,ui) {
location.href = ui.item.the_link;
}; //<-- remove ; incorrect semicolon
}); //<- correct usage
I solved the problem, Netbeans not sync version of my PC with the server.
Thanks anyway to all answers.