Building wikipedia viewer, always get error[Solved]

Building wikipedia viewer, always get error[Solved]
0

#1

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.


#2

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


#3

did both, didnt’t help


#4

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


#5

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?


#6

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


#7

Can you show me a link to it?


#8

#9

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?


#10

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


#11

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


#12

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


#13

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


#14

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


#15

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?


#16

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


#17

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


#18

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


#19

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