<?php if (!empty($ocfilter_pages)) { ?>
<?php if (!empty($ocfilter_pages)) { ?>
<div class="row row-hide">
<div class="col-lg-12">
<p class="heading"><span>Дополнительные категории</span></p>
<div class="wrapper333">
<input type="checkbox" id="button">
<div class="xpandable-block">
<ul class="list-inline">
<?php foreach ($ocfilter_pages as $ocfilter_page) { ?>
<li>
<?php if ($ocfilter_page['selected']) { ?>
<strong><?php echo $ocfilter_page['text']; ?></strong>
<?php } else { ?>
<a href="<?php echo $ocfilter_page['href']; ?>"><?php echo $ocfilter_page['text']; ?></a>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
<label for="button">Показать все...</label>
</div>
</div>
</div>
<?php } ?>
var data = []
$('#txt-search').keyup(async function(){
var searchField = $(this).val();
if(searchField === '') {
$('#filter-records').html('');
return;
}
if (!data.length) {
data = await fetch('url/to/file.json').then(r => r.json())
}
var regex = new RegExp(searchField, "i");
var output = '<div class="row">';
var count = 1;
$.each(data, function(key, val){
if ((val.employee_salary.search(regex) != -1) || (val.employee_name.search(regex) != -1)) {
output += '<div class="col-md-6 well">';
output += '<div class="col-md-3"><img class="img-responsive" src="'+val.profile_image+'" alt="'+ val.employee_name +'" /></div>';
output += '<div class="col-md-7">';
output += '<h5>' + val.employee_name + '</h5>';
output += '<p>' + val.employee_salary + '</p>'
output += '</div>';
output += '</div>';
if(count%2 == 0){
output += '</div><div class="row">'
}
count++;
}
});
output += '</div>';
$('#filter-records').html(output);
});
var dataPromise = fetch('url/to/file.json').then(r => r.json())
$('#txt-search').keyup(async function(){
var searchField = $(this).val();
if(searchField === '') {
$('#filter-records').html('');
return;
}
const data = await dataPromise;
var regex = new RegExp(searchField, "i");
var output = '<div class="row">';
var count = 1;
$.each(data, function(key, val){
if ((val.employee_salary.search(regex) != -1) || (val.employee_name.search(regex) != -1)) {
output += '<div class="col-md-6 well">';
output += '<div class="col-md-3"><img class="img-responsive" src="'+val.profile_image+'" alt="'+ val.employee_name +'" /></div>';
output += '<div class="col-md-7">';
output += '<h5>' + val.employee_name + '</h5>';
output += '<p>' + val.employee_salary + '</p>'
output += '</div>';
output += '</div>';
if(count%2 == 0){
output += '</div><div class="row">'
}
count++;
}
});
output += '</div>';
$('#filter-records').html(output);
});
// Пример отправки POST запроса: postData('http://example.com/answer', {answer: 42}) .then(data => console.log(JSON.stringify(data))) // JSON-строка полученная после вызова `response.json()` .catch(error => console.error(error)); function postData(url = '', data = {}) { // Значения по умолчанию обозначены знаком * return fetch(url, { method: 'POST', // *GET, POST, PUT, DELETE, etc. mode: 'cors', // no-cors, cors, *same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *same-origin, omit headers: { 'Content-Type': 'application/json', // 'Content-Type': 'application/x-www-form-urlencoded', }, redirect: 'follow', // manual, *follow, error referrer: 'no-referrer', // no-referrer, *client body: JSON.stringify(data), // тип данных в body должен соответвовать значению заголовка "Content-Type" }) .then(response => response.json()); // парсит JSON ответ в Javascript объект }