How to make data loading via ajax? I need to start an html document with an ajax request to retrieve several data and write them to the appropriate id.
AJAX request: ( see comments )
$(document).ready(function() { $.ajax({ type: POST, url: 'php/getData.php', data: //что передавать здесь? success: function(data) { // и как правильно получить здесь? $("#userName").text(data[name]); $("#userAge").text(data[age]); } }) return false; });
How to send $ name and $ age data from getData.php to ajax request
<?php require "db.php"; if (isset($_SESSION['logged_user'])) { //Получение данных $name = $_SESSION['logged_user']->name; $age = $_SESSION['logged_user']->age; } else{ header('location ../login.php'); } ?>
Just in case authorization:
<?php require "db.php"; $data = $_POST; $user = R::findOne('users', 'login = ?', array($data['login'])); if ($user) { if (password_verify($data['password'], $user->password)) { $_SESSION['logged_user'] = $user; } else { echo ('Неверный пароль'); } } ?>