0

我正在使用 Wikipedia API 来获取信息并将其显示在我的 Web 应用程序中。

我使用如下 URL 来访问我的 JavaScript 中带有 AJAX 请求的 API。 http://en.wikipedia.org/w/api.php?format=json&action=query&prop=revisions&titles=Barack%20Obama&rvprop=content&rvsection=0&rvparse

但是,在返回的内容中,超链接是使用“/wiki/resource”形式的相对 URL 指定的。现在,当我在我的网页上显示此内容时,URL 变得像

http://localhost:8003/wiki/resource

如何使 URL 重定向到http://en.wikipedia/wiki/resource

提前致谢!

4

1 回答 1

0

连接它前面的基本 URL。例如:

wikiRelativeUrl = getRelativeUrl(); //returns something like /wiki/resource
baseUrl = "http://en.wikipedia";
fullUrl = baseUrl + wikiRelativeUrl;
//use fullUrl
于 2014-04-22T13:44:22.077 回答