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,
Sam
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,
Sam
Hi
This code:
$.ajax({
type: 'GET',
url: 'https://en.wikipedia.org/w/api.php?'+
'action=query' +
'&list=search' +
'&srsearch=' +
searchTerm +
'&format=json',
dataType: 'jsonp',
...
It can be written using the data parameter:
http://api.jquery.com/jquery.ajax/
data
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).
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.
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.
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.