How to store results of search for display (wikipedia project)?

How to store results of search for display (wikipedia project)?


I can successfully search the wikipedia api with the following script:

url: '',
type: 'GET',
dataType: 'jsonp',
data: {
 action: 'opensearch',
 format: 'json',
 search: usr_search,
success: function (data) {


The only thing is, what is the best way to store some number of results for display on the page? Is it best to put them into an array? If so, how can I separate one result article from the next and store them for display later? Any specific examples would be great!


What is it that you’re wanting to do with this data? I would advise against keeping data around unless you absolutely must.


I need to keep the data I get from the JSONP call so that I can display it on the page (just like on the fcc wikipedia search viewer project). I am just unsure of how to split the data up like I would if I had been able to use JSON and stringify(). Basically, I need to find a way to get the search term and a link to appear for each result after a user searches a given term. What is the best way to do this? Any specific examples would be great!


Where do you want the result to appear? It looks as though you are placing it in a paragraph.

Yes, place them in an array, and create a container for the results. You will want the title to connect to the wiki page and bring in at least the first sentence.

You can loop it for an un-ordered list and style each li with borders as separators - or call on paragraphs as you seem to be doing.

Why display later? Don’t you want instant gratification?

You can google to search for some great examples from other FCC coders, and learn from the various styles they use.


I currently have the whole thing appearing in a paragraph because I wasn’t sure how to split up the data. Before now, I was just focusing on correctly getting the data, so the setup is a preliminary one. The problem is that when I try and return parts of the data variable, I don’t seem to get anything useful that I can split up. If anyone could help me with the syntax accessing the parts of the data that is coming in to split up and display, that would be great!


I’m not sure how much this will help…

It works fine except when I type in something that doesn’t have a page (hawaii royalty instead of royal hawaii).

I hope this will lead you in the right direction though.


My advice is to use a different query to the Wikimedia API. It isn’t well documented, but through a lot of trial and error, I came up with a different set of parameters that makes searching much easier. I made a quick demo which should explain the relevant details. KoniKodes has a fantastic project, but you may want a reference that’s a little more bare-bones.


Thanks for the help!


Thanks! This way looks better than the way I was attempting earlier. I’ll let you know what happens with this method.
Thanks again!