I am doing a query in wikipedia to get a snippet and the title with the link. Then if i click a title I would like to get the full article in a modal.
I am trying to get different articles for each different link I get in the first query.
Here it is a JsFiddle
$("#wiki").on('click', function(e) {
var articleName = $(this).data('subject');
$.getJSON("https://it.wikipedia.org/w/api.php?callback=?", {
srsearch: articleName,
action: "query",
list: "search",
format: "json"
}, function(data) {
$("#results ul").empty();
$("#results ul").append("<h3>Results for <b>" + articleName + "</b></h3>").text();
$.each(data.query.search, function(i, item) {
$("#results").append("<li><a href='http://it.wikipedia.org/wiki/" + encodeURIComponent(item.title) + "' data-toggle='modal' data-target='.bs-example-modal-lg'>" + item.title + "</a><br>" + item.snippet + "</li");
var myLink = $("#results ul li a").attr("href");
$("#results div a").attr("href", "#");
$('.modal').on('show.bs.modal', function (e) {
$.getJSON("https://it.wikipedia.org/w/api.php?action=parse&format=json&callback=?", {
page: articleName,
prop:"text"
}, function(data) {
$(".modal-content").html(data.parse.text['*']);
});
});
});
});
HTML
<button id="wiki" data-subject="Paris">Wikipedia</button>
<output id="results">
<ul>
</ul>
</output>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
</div>
</div>
</div>