I have this code, it does an AJAX call to Wikipedia, asking for results of a given query (var searchText):
function main() {
$(".btn").click(function() {
$("#iframe").attr('src', 'https://en.wikipedia.org/wiki/Special:Random');
$(".embed-container").css('visibility', 'visible');
});
function wikiAjax (searchURL) {
return $.ajax({
url: searchURL,
jsonp: "callback",
dataType: 'jsonp',
xhrFields: {
withCredentials: true
}
});
}
$(".search-form").submit(function() {
event.preventDefault();
var searchText = $('#search').val();
var searchURL = "https://en.wikipedia.org/w/api.php?format=json&action=query&generator=search&gsrsearch=" + searchText + "&gsrlimit=15&prop=extracts&exsentences=3&exintro=&explaintext&exlimit=max&callback=JSON_CALLBACK";
console.log(searchURL);
var wikiResponse = wikiAjax(searchURL);
wikiResponse.done(function(data) {
console.log(data);
}).fail(function(err) {
alert("The call has been rejected");
});
});
}
$(document).ready(main);
But it returns me a strange object:
Could someone please help me?