Wikipedia API, JSONP, and the Struggles

Wikipedia API, JSONP, and the Struggles
0

#1

Hey guys! I am still having trouble with using JSONP to get around the cross origin issues… I tried with my last two projects (Weather App and Quote generator) but ended up just using http codepen instead of https to get around the problems.

Now I would like to try using the apis and JSONP correctly.

I’ve been trying to read other people’s issues, and replicate/understand their code but I don’t know what it is about mine that is not working… I am not even seeing any error or messages to the console to help with debugging… I am stuck now. What am I doing wrong or missing?

Here is my codepen: http://codepen.io/sdkevorkian/pen/NdVXPo


#2

When you submit form default action is to refresh the page.
To prevent this default action add:

$("#search-wiki").click(function(e) {
  e.preventDefault();
  ...

Also you are missing & before callback=? in your url.


#3

Thank you so so much!! I see the results in the console.log now :slight_smile:

So was this more of an issue with the form than the JSONP (other than my typo)? what does the “e” refer to that is being passed into the function and then we are preventing the default settings (page reload) of?


#4

e is the event.
You can add console.log(e) and see what it looks like.

Documentation: https://developer.mozilla.org/en/docs/Web/API/Event/preventDefault
Info about events: https://www.w3schools.com/jsref/dom_obj_event.asp


#5

awesome, thank you!!