Help with Wikipedia API (Getting Header related Error)

Help with Wikipedia API (Getting Header related Error)
0

#1

Here is my code pen:

so this is the error I am getting consitently,
Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘https://s.codepen.io’ is therefore not allowed access
All im trying to do for now is get the information from the url on the main page and log it to my console. Apparently i need some sort of header to get access but no matter what I put it doesn’t seem to work. Any ideas on how to fix this?


#2

Add “https://crossorigin.me/” before the wikipedia url


#3

hmm maybe not I just tried it on yours, that’s all I added to mine and it fixed the error


#4

yeah that was one of the first things i tried lol, any idea on what the header is supposed to look like?


#5

So i fixed it by changing my dataType from json to jsonp, for some reason that resolves it


#6

I’m using “$.get” over “$.ajax” and haven’t added and headers to my call. I thought get was just shorthand for $.ajax but they seem to work differently so I’m not too sure. Main thing is you sorted it so well done haha


#7

I believe you are right about that, if your talking about JSON.get method. Weird you didn’t need any headers, on their documentation wikimedia says you do lol.


#8

just $.get, maybe it sorts this out for you automatically. They don’t even mention them in the docs for them https://api.jquery.com/jquery.get/