$.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
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.
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-
$('#searchTerm').keyup(function (e) {
var search = $(this).val();
Then I send the variable search to the opensearch api-
$.ajax({...})
}
Hardcoding the hashtag instead of using a variable works fine- "#". I tried JSON.stringify(search), but it made no difference.