Answer the question
In order to leave comments, you need to log in
How to make a page where data is loaded from the database and loaded via ajax?
In general, the question may be stupid, but I hung up.
I am making an admin. Page of all records from the database. In general, I receive data through a curl request to my server, which specifies the conditions of the request and, most importantly, the api-key, which makes it possible to make requests.
The admin logs in (successfully) and the api-key is written to his session.
The user never sees his api-key at all and does not have it in the public domain. In this case, the key is in the session
Now he gets to the records management page.
I need him to immediately see the unconfirmed entries, which he must check and confirm. It also displays a filter for those records in front of it.
And this is where my confusion begins.
If I display the first page, I can directly in it:
<? $result = api($data, $_SESSION['api_key']) ?>
<div>
<? foreach ($result as $v): ?>
<p>$v['name']</p>
<p>$v['date']</p>
...
<? endforeach; ?>
</div>
<script>
let api = '<?=$_SESSION['api_key']?>';
console.log(api);
// и здесь будет функция, которая сделает fetch запрос на сервер...
</script>
Answer the question
In order to leave comments, you need to log in
Don't plant a garden. When you click on the "apply filter" button (well, or whatever you have), call something like this:
function getFilteredData(filter = []) {
$.ajax({
url: 'site/filterController',
type: 'POST',
dataType: 'json',
data: {
filter: filter,
},
error: function (e) {
// функция если какая-то ошибка
console.log(e);
}
})
.done(function (data) {
// функция обработки полученных данных
console.log(data);
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question