Wikipedia api native javascript

Wikipedia api native javascript
0.0 0

#1

Hello . I can not get normal json data. The information what I receive is not complete.

My code

document.getElementById('search').addEventListener('click',function(val){
    let userInput = document.getElementById('userInput');
    let term = userInput.value;
    let wikiRequest = new XMLHttpRequest();
    
   
    let url = 'https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=god&origin=*&format=json';
    
    wikiRequest.open('GET', url)
    wikiRequest.onload = function() {
        let data = JSON.parse(wikiRequest.responseText);
     
        let array = data.query.search;
        for(var i= 0; i < array.length; i++){
            let output = document.getElementById('output');
            output.insertAdjacentHTML('beforeEnd', '<h3>'+array[i].title+'</h3>' + '<p>'+ array[i].snippet +'</p>' );
            // console.log(array[i]);
        }
        console.log(data);
    }
    wikiRequest.send();
} )

i think problem is in parameters of wiki api what i pointed out. I will be very grateful for any help.


#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

When I run your code, I get a JSON data. What format are you wanting to get exactly?


#4

Hi, I want to receive full information about term what i searching for .


#5

The task is completed. Sorry my mistake. How can I close this topic?