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.

9
  • What does the alert function in your code do? Commented Jun 27, 2015 at 14:12
  • Sorry mistake, removed but still not working. ps. Alert do not shot anything. Commented Jun 27, 2015 at 14:12
  • You still have a semicolon that's a syntax error ? Commented Jun 27, 2015 at 14:13
  • After the select property Commented Jun 27, 2015 at 14:14
  • 1
    Here's a working example -> jsfiddle.net/adeneo/1udLh2cs/2 Commented Jun 27, 2015 at 14:17

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

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

});

1 Comment

Thanks but i already solved the problem, the problem is Netbeans that not sync my copy with server .
0

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

Thanks anyway to all answers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.