2

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.

Mirko Brombin
  • 1,002
  • 3
  • 12
  • 34

3 Answers3

2

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
Community
  • 1
  • 1
1

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;
}

});

alysonsm
  • 1,465
  • 1
  • 12
  • 16
0

I solved the problem, Netbeans not sync version of my PC with the server.

Thanks anyway to all answers.

Mirko Brombin
  • 1,002
  • 3
  • 12
  • 34