function loadPage(argUrl, argType, argParams) {
loadingBar(1);
if (argType == 1) {
argType = "POST";
} else {
argType = "GET";
// Store the url to the last page accessed
if (argUrl != window.location) {
window.history.pushState({path: argUrl}, '', argUrl);
}
}
// Request the page
$.ajax({
url: argUrl,
type: argType,
data: argParams,
success: function (data) {
// Парсим ответ:
var result = $(new DOMParser().parseFromString(data, 'text/html'));
// Скролл вверх:
$(document).scrollTop(0);
// Обновляем титул:
document.title = result.find('title').html();
// Обновляем чисто содержимое блока body:
$('body').html(result.find('body').html());
// Reload functions
reload();
loadingBar(0);
}
});
}
document.querySelector('#test').value = 'Бла-бла-бла';
<div id="block"><? echo time(); ?></div>
<script>
(async function() {
var selector = '#block'; // Селектор блока, который надо обновлять
while (true) {
await new Promise(function(s) { setTimeout(s, 30*1000); }); // Каждые 30 сек.
try {
var html = await (await fetch(location.href)).text();
var newdoc = new DOMParser().parseFromString(html, 'text/html');
document.querySelector(selector).outerHTML = newdoc.querySelector(selector).outerHTML;
console.log('Элемент '+selector+' был успешно обновлен');
} catch(err) {
console.error('При обновлении элемента '+selector+' произошла ошибка:', err);
}
}
})();
</script>
<?php
echo '<form style="display: none;" method="post" action="https://bank.com/payment">';
echo '<input type="hidden" name="order_id" value="1">';
echo '<input type="hidden" name="amount" value="1000">';
echo '<input type="submit" value="Отправить платеж">';
echo '</form>';
echo '<script> document.querySelector("form").submit(); </script>';
var input = document.createElement('input');
input.setAttribute('type', 'file');
input.setAttribute('webkitdirectory', 'true');
input.addEventListener('change', function() {
console.dir(input.files);
for (var n = 0; n < input.files.length; n++) {
var path = input.files[n].webkitRelativePath;
console.log(path);
}
});
input.click();
var text = 'Привет, мир!';
var u8a = new TextEncoder().encode(text);
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var bytes = u8a, i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
console.log(base64);
var text = 'Привет, мир!';
var blob = new Blob([ text ]);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function() {
var base64 = reader.result.split(',')[1];
console.log(base64);
};