Wikipedia Viewer App Ajax Error

See the Pen aWEryX by Rob (@eolculnamo2) on CodePen.

For some reason my AJAX function isn’t working on my app. I can’t figure it out. Any ideas?

what exactly are you trying to figure out? i see you’re talking to the API. are you having trouble printing the data to the web page?

Yes. Nothing will go to the page. I’m pretty baffled. It’s logging the API in the console.

okay, two things first off. i haven’t figured out everything your code is trying to do, but it’s certainly a start.

in your url to query the wiki api, you are requesting JSON, so you include origin=* (which resolves the CORS issue) and then you add on &callback=? which is to request the data in JSONP format. you need one or the other, but not both. since in your function, you’re requesting JSON, i just took off the &callback=? in the fork i made.

change the console.log(data) you have commented out to console.log(data[1]) to see the difference.

the next thing i noticed is in the for loop, you have i < data[1], but for it to work as i think you want, you’ll need i < data[1].length

oh, and you’ll need a $ character before (".text").prepend since it’s a JQuery command.

eg $(".text").prepend("…");

lastly, i’d prolly use $().append here since it adds the next result to the end instead of the front like prepend does. i would choose this because the wiki results usually are ordered in terms of relevance. just my two cents.

any other questions, let me know!

$("#text").prepend(“FUCK”); lol lol … this dosent work

for(i=0; i < data[1].length; i++){ // you forgot to add the .length in this line
$("#text").append("<li><a href= " + data[3][i] + ">" + data[1][i] + "</a><p>" +data[1][i]+"</p></li>");
i added the $ you forgot that … you were also using $(’.text’) instead of $(’#text’) … i changed prepend to append … and now the result shows up on your page.
Hope this helps

Thanks guys! I’ll give all that a go!

And I’m sorry for the vulgar bit I left in the code. I should have taken it out before posting on here. lol

Thanks to both of you! It got me over the hurdles. Looks like I have a lot of learning to go!