I’ve been moving through the course at a pretty good pace, but when i got to the wiki viewer asignment for some reason that all changed. It has been one struggle after another with this one. Please i’m not looking for an answer i want ot beat this SOB on my own. but if you could please point me in the right direction I would be very happy!
here is my code: ( forgive the style i have only worked on features thus far )
Some ofthe problems i’m having:
- some but not all queries will return multiple results but when you click on them they all link to the page that the first result should link to. ( searching “dog” always seems to cause this while “cat” almost never causes it )
- I have a loop that should clear out all results if a new search is made but instead it just adds the new search to the bottom of the list.
Thanks again for any pointers you can share with me
Are you particular about using the while method to remove results of previous searches…? I can understand the logic that you’re trying to execute i.e. when a first child exists the value will return true and the while loop will execute to remove the first child until all results are emptied. I can not find what’s really wrong as I am not that experienced with those methods. But if you want a simpler method, try using the .empty() method on your div that holds the search results instead.
var list = document.getElementById("searchResults");
I used the same logic, but different methods, and it worked. Will try to find out why yours did not work when I get back. Or you can share with me if you do find it first.
Awesome Thanks for the response! i switched the while loop out for empty() as suggested. This seems like the “official” way to handle it and it works great! THANKS! I’m still having issues with search results not linking as they should.
You’re welcome I noticed that the links lead to the wrong page only when the article you’re clicking has a space in them. What’s happening is that if you click on Dog Tag, what comes after the space is eliminated and you’re taken to the page ‘Dog’.
Holy bacon bits Batman you are a genius!!! How did i not catch that?? That has to be a huge clue
The problem with my code was that when creating the links in the result i was building the links like: “www.wikipedia.org/wiki/” + json[i] where json[i] == the title of the page. After BlueCodeA pointed out the spaces thing i went back and looked and realized the json they give you provides the proper links anyway… so i changed the link to json[i] which is the proper link and now all is well! Thanks again BlueCodeA!
Awesome… I’ve received a lot of help along the way, so it’s nice to give back for a change…