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
PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals.
This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati
CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu
Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems.
With a large collection of extensions for many programming languages, VS Code can be c
CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an