Difference between revisions of "Main Page"

From Networks of Care
Jump to navigation Jump to search
Line 8: Line 8:
  
 
<script>
 
<script>
 
+
$params = new DerivativeRequest(
var apiEndpoint = "https://en.wikipedia.org/w/api.php";
+
    $this->getRequest(), // Fallback upon $wgRequest if you can't access context.
var params = "action=query&list=random&rnlimit=3&format=json";
+
    array(
 
+
        'action' => 'query',
/**
+
        'list' => 'allpages',
* The function to wrap the result
+
        'apnamespace' => 0,
*/
+
        'aplimit' => 10,
var callback = function (response) {
+
         'apprefix' => 'L'
    var pages = response.query.random; // Process the output to get the titles
+
     )
    Object.keys(pages).forEach(function(key) {
+
);
         console.log(pages[key].title);
 
     });
 
};
 
 
 
var scriptTag = document.createElement("script"); // Dynamically create a "script" tag
 
scriptTag.src = apiEndpoint + "?" + params + "&callback=callback"; // Point to the query string
 
 
 
document.body.appendChild(scriptTag); // Add the script tag to the document
 
 
</script>
 
</script>
 
</body>
 
</body>
 
</html>
 
</html>

Revision as of 14:59, 6 April 2020