$app->get('/api', function(Request $request, Response $response) {
// тут просто выводит шаблон
}
$app->get('/api/customers', function(Request $request, Response $response) {
// а тут выводит выдачи всех покупателей
}
$app->any('/panel/post', 'App\Controllers\AdminController:all_post') //основной шаблон, вывод всех постов
public function all_post(Request $request, Response $response, $args)
{
$stmt = $this->pdo->query("SELECT * FROM `post` ORDER BY `post`.`id` DESC");
$posts = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $this->view->render($response, 'admins/xhrHTML.twig');
}
$app->any('/panel/post/one', 'App\Controllers\AdminController:post_one')
public function xhrHttp(Request $request, Response $response)
{
$post = [
'file' => 'file.txt'
];
return $response->withJson($attr);
}
console.log(typeof data)
что выводит? return $response->withJson($customers);
var xhr = new XMLHttpRequest();
xhr.open('GET', '/api/customers', true);
xhr.onload = function (data) {
console.log(JSON.parse(data.target['response'])) // Object
document.body.innerText = JSON.parse(data.target['response']).customer
};
xhr.send();
data: {str:str}