我有一个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
方法?谁能告诉我解决方案?
答案 0 :(得分:2)
您想让自己看起来简单...
<?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>