Building wikipedia viewer, always get error[Solved]

I can’t seem to get it working, I followed other code when mine didn’t seem to work, and it didn’t get success too, I then written it letter to letter, still can’t get success. The url works great, I can put it in browser and it will show me the array which I need.

The url is missing a callback &callback=?.also put quotes around false async:"false",

did both, didnt’t help

There is problem with the button event on(“click”), you should try to figure out why it doesn’t work.

Looks like your action type in the API URL is incorrect.

In the URL, use “action=query” instead of “opensearch”.
You’ll also need to adjust a few other parameters in the URL accordingly. See https://www.mediawiki.org/wiki/API:Query
If you’re getting back an object with “query” as one of the keys, you’re good to go from there.

I think “opensearch” is used to auto-fill the search box as you type?

Then why does it work for other people with the same action type of opensearch?

Can you show me a link to it?

Oops sorry, yes your way should work also. I hadn’t used “opensearch” before so you taught me something new. Thanks!
Anyway yeah your variable “data” contains the info you need. From there you have to use that info and write the result to HTML… is that where you are having trouble?

The problem is that, I can’t get access to that data, the success function doesnt work, and always goes to the error function, i just want for now to see the array of items in the console, to know it will work

Really. That’s strange because it works for me when I run your code.
If you add error handling code like this, you’ll hopefully get some useful info:
https://stackoverflow.com/questions/6792878/jquery-ajax-error-function

Looks like I get: "Requested page not found. [404]". I tried on different browser too, same result

If you console.log the url right before the ajax call, it looks correct?

Yes, it does look fine, works in the browser too, shows the Json

Hmmm. Honestly why this is happening only for you is beyond my knowledge. Sorry. At least you know it’s a 404 you’re getting back, so it’s most likely something with URL. Search google and this forum (“ajax api 404” etc…). I did a quick search and found this: Wikipedia viewer API, Jquery does send query to servers Not sure if that’s it though.

Or maybe someone else who is more experienced than me would like to chime in?

Tried with the getJSON() method, still same problem, https://codepen.io/daugiss/pen/EvgdVv, maybe the code is bad

@daugiss check this out!https://codepen.io/madhurisoni12/pen/XaNBRP?editors=0011 changed button to input

well that’s interesting, it really works, thanks a lot!!

I’ve fixed the problem, I just had to add type="button" to the button, and it works 100% for me now.

1 Like