<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form>
<input type="text" name="bookTitle" placeholder="Название книги" id="bookTitle" required autofocus>
<input type="button" name="submit" value="Найти" id="submit">
</form>
<div id="results"></div>
<script>
document.addEventListener('DOMContentLoaded', start);
function start() {
document.getElementById('submit').addEventListener('click', searchBook);
}
function searchBook() {
let bookTitle = document.getElementById('bookTitle').value;
let params = 'bookTitle=' + bookTitle;
let resultsContainer = document.getElementById('results');
checkLibrary(params, 'one', resultsContainer);
checkLibrary(params, 'two', resultsContainer);
}
function checkLibrary(params, library, resultsContainer) {
params += '&library=' + library;
let xhr = new XMLHttpRequest();
xhr.open('POST', 'server.php');
xhr.onreadystatechange=()=>{
if (xhr.readyState === 4) {
if (xhr.status === 200) resultsContainer.innerHTML += xhr.responseText;
else alert('Ошибка: ' + xhr.status);
}
};
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhr.send(params);
}
</script>
</body>
</html>
<?php
$bookTitle = $_POST['bookTitle'];
switch ($_POST['library']) {
case 'one':
checkLibraryOne($bookTitle);
break;
case 'two':
checkLibraryTwo($bookTitle);
break;
}
function checkLibraryOne($bookTitle) {
sleep(1);
echo 'Деловая библиотека';
}
function checkLibraryTwo($bookTitle) {
sleep(5);
echo 'Библиотека Некрасова';
}
memory_limit = 256M
upload_max_filesize = 32M
post_max_size = 32M
realpath_cache_size = 8M
magic_quotes_gpc = Off
date.timezone = "Europe/Moscow"
short_open_tag = On
session.save_path = "/tmp/u0057069"
mail.log = "/var/www/vhosts/u0057069.plsk.regruhosting.ru/sidorchik.ru"
https://maps.googleapis.com/maps/api/geocode/json?key=QWERTY1234&address=Москва,%20ул.%20Академика%20Бочвара,%202