Wikipedia Viewer - Formatting Results

Working on my Wikipedia Viewer and was able to get the search term to show results on my page. Trouble is, I’m having a hard time figuring out how to get the information from the array so I can show the extracts from my search query. I have a feeling it has something to do with the way I set up my for loop, but I’m not entirely sure.

Here’s my codepen with what I have so far:

I’m no expert on this, but since no one else has answered, I’ll give it a shot…

I changed your ajax call to fit what I did.

   var url = '' +
		'?callback=?' +
		'&action=opensearch' +
		'&format=json' +
		'&profile=fuzzy' +
		'&limit=10' +
		'&prop=imageinfo&format=json&iiprop=urll' +
		'&search=' + encodeURI(query);
    $.getJSON(url ,function(json) {
      console.log("\n\nfull json...\n");
      console.log("\n\njson[0], search string...\n");
      console.log("\n\njson[1], array of article headings...\n");
      console.log("\n\njson[2], array of article descriptions...\n");
      console.log("\n\njson[3], array of page URLs...\n");


I changed the URL to what I had. Yours seemed to be giving back results in a different format. I don’t know why. the results didn’t look like what a JSON looks like to me (based on my limited understanding). I wrapped your query in encodeURI() - a good idea so some strange input (like a space) doesn’t screw up your search.

This yields back a JSON with several arrays. array 1 is the titles, 2 the descriptions, and 3 the URLs. You can get a closer look in your console.

Hope this gets you a step closer.

This definitely has helped! I didn’t have the part where ‘&profile=fuzzy’, so I’ll have to look up what that means. But at least now I have results I can actually read.

Thanks for the help! :slight_smile:

It looks like the ‘&profile=fuzzy’ has to do with spell correction in the search string. I don’t think it was the problem.

I’m not sure why, but your search string wasn’t returning a JSON object (by my understanding.) I can’t remember, where you doing opensearch?

directly under the below line of code place the following …
console.log("\n\njson[3], array of page URLs…\n");

var text ="<h2> Results for: " + query + "</h2> <br/>"+json[2]+"</p"

Lol think your working on it as im checking it … so add below the text … in-between the lines above … … should have said add the text in bold above thats in between the lines … under text below … you can then remove that text below as well.

 ``` var headings = json[1].length;
  for(i = 0; i < headings; i++) {
      '<h2> Results for: "' + query + '"</h2> <br/> ' +
      '<p>' + headings[i] +'</p>'

I wasn’t. I was using the Wiki Sandbox to create the url for the search that was linked on the challenge main page.

Lolz. Probably. I try something, save it so I can reference it again, then try something else. I guess it’s programmer fidgeting. :joy:

@JohnL3: Thanks for your help! This actually did what I wanted it to do, which is show the urls on the page.

Any ideas on how to get them to show up as a list? I’m thinking I need to do a loop to get them to show up correctly. Or maybe a “span” within the “p” tag to separate out the values.

I’m not sure. I think I need a break from this for the day since I’ve been working on it for almost 4 hours. But I’m making progress, so thank you again. :slight_smile:

heres a quick bit of code to help you … as im going off my computor for a while but you should be able to make a start with this … plus look up … append …
Check out this quick repl first

This is plenty! Thank you! I’ll definitely have a ton to work off of tomorrow.
Thank you for all your help! I really appreciate it! :slight_smile:

Boom! Got it to work! Thanks goes out to @ksjazzguitar and @JohnL3 for helping me out with this. I really appreciate it! :slight_smile: