$.ajax({
url: "https://en.wikipedia.org/w/api.php",
dataType: "jsonp",
data: {
'action': "opensearch",
'format': "json",
'search': search
},
success: function (data) {
var suggestions = '';
data[1].forEach(d => {
suggestions += `<option value="${d}">`;
});
console.log(data);
$('#searchList').html(suggestions);
console.log(suggestions);
}
});
Difference between hashtag symbol from wikipedia search api and local server(来自Wikipedia搜索API的主题标签符号和本地服务器之间的区别)
In other words the datalist populates just fine normally with other characters including @ or $, but when using # it will not drop down and show the suggestions even though the datalist is populated with the correct items when inspecting the element.(换句话说,数据列表通常可以正常填充其他字符,包括@或$,但是使用#时,即使检查元素时数据列表中填充了正确的项目,它也不会下拉并显示建议。)
edit: by localhost I meant I changed the endpoint to my server so I could see what would happen if I sent back the option list with a hashtag.(编辑:通过本地主机,我的意思是我将端点更改为服务器,因此可以看到如果将带有井号的选项列表发送回去会发生什么。) It worked fine and I noticed the different font between the hashtags sent by my server vs wiki's opensearch.(它工作正常,我注意到服务器发送的主题标签与Wiki的opensearch之间的字体不同。)
edit: The search variable comes from the input box like this-(编辑:搜索变量来自像这样的输入框-)
<form class="pSearch form-inline" method="post" action="">
<input class="pSearch" type="text" id="searchTerm" name="searchTerms" placeholder="Search" aria-label="Search"
list="searchList" autocomplete="off" spellcheck="true">
<datalist id="searchList"></datalist>
I listen for input with the keyup function-(我用keyup功能收听输入-)
$('#searchTerm').keyup(function (e) {
var search = $(this).val();
Then I send the variable search to the opensearch api-(然后,将变量搜索发送到opensearch api-)
$.ajax({...})
}
Hardcoding the hashtag instead of using a variable works fine- "#".(硬编码主题标签而不是使用变量可以正常使用“#”。) I tried JSON.stringify(search), but it made no difference.(我尝试了JSON.stringify(search),但是没有区别。)
ask by jmoney translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…