У меня demo.php, в нем кнопка:
<?php
include('../library/Requests.php');
Requests::register_autoloader();
function get_data(){
$request = Requests::post('http://localhost:8000/api/groups/list/', array(), null);
var_dump($request);
}
?>
<button>Click Me</button>
Как я могу запустить метод get_data в моем demo.php? Кто подскажет решение?






Вы должны смотреть простые вещи ...
<?php
include('../library/Requests.php');
Requests::register_autoloader();
// check whether form is submitted or not on same page if submitted then call get_data() function
if (isset($_POST['submitBtn']))
{
get_data();
}
function get_data(){
$request = Requests::post('http://localhost:8000/api/groups/list/', array(), null);
var_dump($request);
}
?>
// make form that could send request
<form action = "" method = "post">
<button name = "submitBtn" type = "submit">Click Me</button>
</form>
Вы можете использовать ajax ... означает, что вы должны отправить запрос на сервер в форме HTML
Могу я не использовать <form>?