I’m working on the wikipedia viewer project and am having trouble trying to get the api to search the results from my form input. The “result” variable represents my input value from my index page.
The code seems to work fine if I hard code something into the search field in the request header. You’ll see the word “hello” there now. I’ve been trying to somehow use “result” in that field by using string concatination but the an error in the console that says “search must be set”. I’m not sure how to alter the header in such a way to fit that variable in there. Help will be appreciated.
$('#search').keypress(function () {
let result = document.getElementById('search').value;
$.ajax({
url: 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=hello&prop=revisions&rvprop=content&formatversion=2',
dataType: 'jsonp',
type: 'GET',
success: function (data) {
console.log(data);
for (var i = 0; i < 10; i++) {
$('.container').append('<div class="content">' + data[1][i] + '<br><br>' + data[2][i] + '</div>');
}
}
});
});```