<!DOCTYPE html>
<html>
<body>
<h1>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="Wiki.css">
<script src = "Wiki.js"></script>
<input id="input" type="text" size="40">
<button class="button button1" id = "getSearch" > Search</button>
</input>
<div id="output"> </div>
</h1>
</body>
</html>
//Run some JQuery
$(document).ready(function(){
//When search is clicked run code
$("#getSearch").click(function(){//button reacts to click
//get search input
var input = $('#input').val();// <input> reacts to what is typed.
console.log(input)
//complete api
var html = "https://en.wikipedia.org/w/api.php?action=opensearch&search=lol&format=json&origin=*&srsearch="
+ input; //complete url
console.log(html);
$.ajax({
url:html,
dataType: 'json',
async:false,
type: 'get',
success: function(data){
$("output").html('');
for (var i = 0; i < data[1].length; i++){
$("#output").prepend("<div class='jumbotron'><li><a href='"+ data[3][i] + "'>"+ data[1][i] + "</a><p>\n" + data[2][i] + "</p></li></div>");
}
$("#input").val("");
},
error:function(errorMessage){
alert("Error");
}
});
});
});
Above is my html and javascript code for the wiki finder. However, i cannot get it to work properly no matter what i do. It keeps giving me the same search result for “lol” no matter what. I’m deeply confused here, and help would be extremely appreciated.