I am embedding Wikipedia articles into my website using the following code.
- It works correctly if I insert a phase that comes directly from a page's URL as the
wiki_links_extract
. - It does not work correctly if I insert a phrase from a page that then redirects to the page of interest. Instead of returning the page contents, it returns the words "Redirects to"
Eg.
https://en.wikipedia.org/wiki/B._21 -- B._21
does not work
https://en.wikipedia.org/wiki/King_and_Charcoal_Burner -- King_and_Charcoal_Burner
works.
Can I modify my script to wait until the redirecting is completed, and then returns the final page?
var url_start =
"https://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&page=";
var url_middle = wiki_link_extract;
var url_end = "&callback=?";
var full_url = url_start + url_middle + url_end;
$.ajax({
type: "GET",
url: full_url,
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function (data, textStatus, jqXHR) {
var markup = data.parse.text["*"];
var blurb = $("<div></div>").html(markup);
$(".article-content-main").html($(blurb).find("p"));
},
error: function (errorMessage) {},
});