I've found impossible to retrieve both description and url at once, so I split in two javascript method, the first get description, the second get url:
function get_wiki_info() {
$.ajax({
url: 'http://it.wikipedia.org/w/api.php',
data: { action: 'query', list: 'search', srsearch: $("input[name=city]").val(), format: 'json' },
dataType: 'jsonp',
success: function (data) {
console.log('wiki', data.query.search[0].snippet);
$('#info-wiki-text').html(data.query.search[0].snippet);
get_wiki_links();
},
fail: function (data) {
$('#info-wiki-text').html("Impossible retrieve information for " + $("input[name=city]").val());
}
});
}
function get_wiki_links() {
$.ajax({
url: 'http://it.wikipedia.org/w/api.php',
data: { action: 'query', generator: 'allpages', search: $("input[name=city]").val(), format: 'json', gapfrom: $("input[name=city]").val(), gapto: $("input[name=city]").val(), prop: 'info', inprop: 'url' },
dataType: 'jsonp',
success: function (data) {
console.log('wiki', data.query.pages);
$.each(data.query.pages, function (key, val) {
$('#wiki-city-link').attr('href', val.fullurl);
});
},
fail: function (data) {
console.log(data);
}
});
}
If you prefer, to retrieve description:
https://it.wikipedia.org/w/api.php?action=query&list=search&srsearch=Your%20Params&utf8=
to retrieve url:
https://it.wikipedia.org/w/api.php?action=query&generator=allpages&search=Your%20Params&gapfrom=Your%20Params&gapto=Your%20Params&prop=info&inprop=url&utf8=