API Википедии не возвращает никаких данных

1

Я пытаюсь получить данные из API Википедии, но я не могу вернуть данные. Я думаю, проблема связана с URL-адресом, но я не знаю. Я изменил URL. У меня был URL-адрес

url = " https://en.wikipedia.org/w/api.php?&action=opensearch&search= " + searchItem + "& format = json & orgin = *";

url = " https://en.wikipedia.org/w/api.php?&action=opensearch&search= " + searchItem + "& format = json & orgin = * & callback =?";

$(function(){

    
    $('#search-click').click(function(){ 
    	var searchItem = document.getElementById('input-search').value;
    	console.log(searchItem);
    	console.log('clicked');

    	var url = "https://en.wikipedia.org/w/api.php?&action=opensearch&search=" + searchItem +"&format=json&callback=?";
    	$.ajax({
    		type:"GET",
    		url: url,
    		async: false,
    		dataType: "jsonp",
    		success: function(data){
    			console.log('Success.');
    		},
    		error: function(error){
    			console.log('Error. Cannot Load Data.');
    		}

    	});

    });
});
body, html{
	padding: 0;
	margin: 0;
	background-color: #16324f;
	color: #d6d9ce;
	text-align: center;
	width: 100%;
} 
h1{
	text-align: center;
	color: #d6d9ce;
	font-size: 50px;
}
h3{
	text-align: center;
	font-size: 30px;
	color: #d6d9ce;
	padding-bottom: 0;
	margin-bottom: 5px;
}
.center div{
	margin: 0 30%;
}
form{
	padding: 10px;
	margin: 10px 10px;
	display: inline-flex;
}
#search-click img{
	padding-left: 10px;
	vertical-align: middle;
}
#input-search{
	padding: 10px;
	width: 400px;
	color: #16324f;
}
input{
	border-radius: 25px;
}
#random-search img{
	margin: 0 50%;
}
footer{
	margin-top: 100px;
}
footer a{
	text-decoration: none;
	color: #d6d9ce;
	text-align: center;
	font-size: 20px;
}
<!DOCTYPE html>
<html>
<head>
	<title>Wikipedia Viewer</title>
	<link rel="stylesheet" type="text/css" href="wikipediaviewer.css">
</head>
<body>
	<header><h1>Wikipedia Viewer</h1></header>
	<div class="center">
		<div>
			<form id="form">
				<input id="input-search" type="text" name="search">
				<a id="search-click" href=""><img src="https://png.icons8.com/ios/51/f49d37/search-filled.png"></a>
			</form>
		</div>
		<div>
			<h3>Random Search</h3>
			<a id="random-search" href="https://en.wikipedia.org/wiki/Special:Random" target="_blank"><img src="https://png.icons8.com/ios/51/d6d9ce/search-filled.png"></a>
		</div>
	</div>
	<div>
		 
		<ul id="wikipedia-links"></ul>
	</div>

	<footer>
		<a href="https://icons8.com">Icon pack by Icons8</a>
	</footer>

	<!-- JQUERY -->

     <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
     <script type="text/javascript" src="wikipediaviewer.js"></script> 
</body>
</html>
  • 1
    Вы запускаете эту страницу с http-сервера? Если это так, вы не можете загружать содержимое https через http-соединение.
Теги:

1 ответ

0

Я попробовал тот же API без пользовательского интерфейса, и он работает нормально.

Дайте мне знать, если я что-то упустил, вот фрагмент -

$(function() {


  $('#search-click').click(function() {
    var searchItem = document.getElementById('input-search').value;

    var url = "https://en.wikipedia.org/w/api.php?&action=opensearch&search=" + searchItem + "&format=json&callback=?";
    $.ajax({
      type: "GET",
      url: url,
      async: false,
      dataType: "jsonp",
      success: function(data) {
        console.log(data);
      },
      error: function(error) {
        console.log('Error. Cannot Load Data.');
      }

    });

  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" id="input-search" value="JavaScript" />
<input type="button" id="search-click" value="search" />

Ещё вопросы

Сообщество Overcoder
Наверх
Меню