问题
I want to make a nodejs, expressjs and jquery search bar which shows article titles and then opens a related webpage in order to selecting the word. My code is:
form.form-inline.my-2.my-lg-0
input.form-control.mr-sm-2(id="tags", type='text', placeholder='Search', aria-label='Search')
button.btn.btn-secondary.my-2.my-sm-0(type='submit')
And my autocomplete.js file is here also:
$('#tags').autocomplete({
source: function(req,res) {
$.ajax({
url: "http://localhost:3000/",
dataType: "jsonp",
type: "GET",
data: {
term: article.title //I am not sure
},
success: function(data) {
res($.map(data, function(item) {
return {
label: article.title,//text comes from a collection of mongo
};
}));
},
error: function(xhr) {
alert(xhr.status + ' : ' + xhr.statusText);
}
});
},
select: function(event, ui) {
window.location.replace("/article/" + ui.item.id);
}
});
Can you solve this problem.
来源:https://stackoverflow.com/questions/59567352/node-js-jquery-opening-a-new-webpage-just-like-happens-in-the-dictionaries