Home  >  Article  >  Web Front-end  >  How to connect html page to php file

How to connect html page to php file

清浅
清浅Original
2019-04-29 10:47:1129216browse

The method for an HTML page to call a PHP file is to use JavaScript. When generating a static page, a corresponding JavaScript file can be generated for the html page based on the database ID to call the PHP file.

How to connect html page to php file

The method for an HTML page to call a PHP file is through JavaScript. When generating a static page, a corresponding JavaScript can be generated for the html page based on the database id. file to call the PHP file.

It seems that the static page cannot directly call the PHP file, but sometimes we can call the PHP file through js. Next, we will introduce it in detail in the article, which has certain reference value. I hope to Everyone helps.

[Recommended course: PHP Tutorial

html itself cannot handle dynamic requests , to complete the call to the PHP file, you need to borrow JavaScript to achieve it. When generating a static page, you can generate a corresponding JavaScript file for the HTML page based on the database ID.

Example

If an HTML file is 123.html, then generate a

<script type="text/javascript" src="click.php?id=123"></script>

on this page and then click.php This page just needs to process and operate the database according to the syntax of PHP.

Example

In page a.html, you can pass the action=test parameter to b.php through the following code

Javascript code

<script type="text/javascript" src="b.php?action=test"></script>

b.php code

<?php
$action=$_GET[&#39;action&#39;];    
echo "document.write(&#39;".$action."&#39;);n";   
?>

When the a.html file is executed, the b.php file will be called, and the output of the b.php file will be executed as a JS statement. The content is the value of the action parameter passed by JS, which is the value of the action received in the PHP file

Summary: The above is the entire content of this article, I hope it will be helpful to everyone.

The above is the detailed content of How to connect html page to php file. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use js in html5?Next article:How to use js in html5?