I want to make autocomplete and I have a problem with this code, I can not make it work, any help would be nice. I want select the title from the autocomplete suggestion and go to the specific URL. Thank you all.
$(function() {
$.getJSON("https://localhost/wp-json/wp/v2/alljobs/", function(data) {
$("#autocomplete").autocomplete({
source: data,
select: function(event, ui) {
window.location = ui.title.rendered;
}
});
});
})
<input type="text" id="autocomplete" />
Any help would be appreciated.
This
window.location = ui.title.rendered;
Should be
window.location.href = ui.title.rendered;
Then it should work.
window.location
returns an object
console.log(window.location)
window.location.href
returns the current url .
If you overwrite it using
window.location.href = "Your url";
The browser will redirect you to the new url
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.