1 Call PHP files using JS and get the value in php
Give a simple example to illustrate:
For example, in page a.html, use the following sentence to call:
alert(jstext);
There is this piece of PHP code in b.php:
$action=$_GET['action']; //echo "var jstext='$action'"; //Output a JS statement, generate a JS variable, and assign the value to the PHP variable $ The value of action //echo "var jstext='aa'"; echo "var jstext="."'$action'"; ?>
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, so a prompt box will pop up here with the value of the JS variable jstext. That is the value assigned to jstext in the PHP file.
Summary:
Use JS to call the file in HTML to call the PHP file, then the output of the PHP file will be used as JS code by the calling page.
//echo ""; //Sometimes it needs to be executed in PHP During the process, a JavaScript custom function needs to be called (an error occurred during verification)
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