Wiki api help needed

Wiki api help needed
0

#1

Hello i am confused , i am not able to use the wikipedia api…my console is not showing me data.following is my code please help.

i think that after changing my api link the problem is occourring in the search term, my data item written in the input feild is not going in the variable search term i provided.

$(document).ready(function(){
  
  $("#search").click(function(){
    
    var searchTerm=$("#searchTerm").val();
    
    var url="https://www.mediawiki.org/wiki/w/api.php?action=opensearch&search="+searchTerm+"&format=json&callback=?";
    
    $ajax({
      
      type:"GET",
      url:url,
      dataType:"json",
      success: function(data){
        console.log(data);
      },
      error: function(errorMessage){
        alert("Error");
      }
      
    });
    
  });
  
});

#2

My api method request url is different

var url = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=" + input + "&callback=?"

#3

Hey @Akshay55,
I would suggest consulting Wikipedia’s API documentation, since I do not think that is the correct URL to make calls.

https://www.mediawiki.org/wiki/API:Main_page

https://www.mediawiki.org/wiki/API:Tutorial


#4

thank you very much for your replies…i appreciate the help… my code still not worked after using @tj9027 api call…:smiley: Thank you.


#5

oh it worked now thank you everyone :smiley:


#6

@Akshay55 would you include the link to your code? Im trying to understand how you got your solution, I am encoutering the same problem.


#7

Here you go…:grinning:


#8

I’ve edited your post for readability. When you enter a code block into the forum, 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.