A Simple, Google-ish Wikipedia Search Project

Hi All,

I would love to hear critique of my wikipedia viewer, be it about design, clarity/function of code, or anything else that comes to mind.

Thank You x 1 million,

Hi :slight_smile:

This code:

      type: 'GET',
      url: 'https://en.wikipedia.org/w/api.php?'+
      'action=query' +
      '&list=search' +
      '&srsearch=' + 
      searchTerm +
      dataType: 'jsonp',

It can be written using the data parameter:


Type: PlainObject or String or Array
Data to be sent to the server. It is converted to a query string, if not already a string. It’s appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

1 Like

I like it, simple and nice.

You may add some handling for entry not found situations. For example, if I search for “;lckmds” it just isn’t showing anything, but would be nice if it would write something like “couldn’t find this entry, try to search for something else”. I haven’t implemented this myself yet, but I think it can be easily done with checking json properties like “if (data.query.search == null)”.


Thanks Erretres! I’ve updated the query to use the data parameter. I like separating the base url from the query; that’s much cleaner.

1 Like

Thanks svmi! I added a little error handling message for entry not found. It turns out data.query.search will still have an array assigned to it, though the array will be have a length of 0. This is helpful to consider for all API-related projects. When I go back to review my projects I will definitely try to sort out the specific error scenarios and make helpful responses on the page.

[quote=“swfisher, post:5, topic:28696”]
It turns out data.query.search will still have an array assigned to it, though the array will be have a length of 0
[/quote]Good to know, will use it. I am trying to handle possible errors, if I figure out they can happen)

Oh, by the way, since you are doing this:

function banishBtns(){ $('.searchBtns').animate({opacity: '0'},0); }

it gives a funny effect. When I searched and received my result, I cannot see the buttons, but if I accidentally click on their place, they will work and, for example, suddenly send me to random wiki article. This is because they are invisible, but still exist where they are.

1 Like

Thank you! Excellent bug catch… I would not have seen that without your help. Perhaps I can either dynamically generate the buttons or figure out a way to disable their function. I’ll let you know what I end up with.

I went with removing the opacity animation altogether & I replaced it with dynamically generated buttons. In order to bind the events needed for the buttons to function, I created a delegated event using jQuery’s $(‘parent’).on(‘event’, ‘child’, function(){…}) syntax.