Wikipedia API not showing

Wikipedia API not showing
0.0 0

#1

Hi guys, i need yet another help with my project.

So i already made the wikipedia API link using opensearch and it work, it show the json on the browser.
However, when i use it on my code, sometimes it appear but most of the time it didn’t. Especially when i add click or submit function, it just didn’t work, nothing happens. I already tried several click function, but still the same.
Is it the link that is not working or is it the code? Please help me guys, i have search online but still nothing has worked.

$("form").submit(function(){
	
	var searchURL = 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=' + document.getElementById("inputsearch").value + '&limit=10&callback=?';
	
$.ajax({
	url: searchURL,
    success: function(data) {
		console.log(data[2][1]);
		$('p').html(data[2][1]);
	},
});
});

#2

Your page is refreshing on submit. Add an event parameter in the submit handler then call event.preventDefault(), like

$('form').submit(function(event) {
  event.preventDefault();
  // ... rest of the code
});

You’d be then hit with a CORS problem, but someone wrote about how to deal with it here:


#3

Awww damn, it works like magic!

Thank you so much!