Home > Article > Backend Development > Can html trigger php functions?
Can html trigger php functions?
html cannot trigger php functions. HTML is a hypertext markup language, which is only used to build the page structure. It cannot trigger a certain function of php.
To trigger a certain function of PHP, we have the following implementation methods:
● Use JavaScript to send an ajax request and trigger a certain function of PHP.
● Use the a tag to refresh the page and bring some parameters to trigger a certain function of PHP.
The specific implementation method is as follows:
1. Use Ajax to trigger php functions
(1) JavaScript code
var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log(this.responseText) } }; xmlhttp.open("GET", "test.php?func=sayHi", true); xmlhttp.send();
(2) test.php file
<?php if ($_GET['func'] == 'sayHi') { sayHi(); } function sayHi () { echo "hello world" } ?>
2. Use a tag to trigger php function
(1) HTML code
<a href="http://localhost/test.php?func=sayHi">触发php函数</a>
(2 ) test.php file is the same as above
Recommended: "PHP Tutorial"
The above is the detailed content of Can html trigger php functions?. For more information, please follow other related articles on the PHP Chinese website!