Home>Article>Web Front-end> Examples of how JS calls PHP and PHP calls JS
Examples of how JS calls PHP and PHP calls JS
When learning any programming language, we will hear the word call. So, how to call php in javascript? Can js also be called in php? Let us take a look below.
1. Call the PHP file using JS and obtain the value inPHP## A simple example to illustrate:
For example, in the page test_json1
,uses the following sentence to call:
Intest_json## There is such a piece of PHP code in #2.php:
When executed
test_json1.php file, thetest_json2.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, the content is the value of the JS variable jstext, which 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 by the calling page as JS code.
2. PHP calls the value in JS
There is such a piece of code in the test_js
on3.php page:##
echo ""; ?>
3. PHP calls methods (functions) in jsIt is basically similar to the second case, using echo scripts to implement JS calls
test();"; ?>
(1)
5. JS calls PHP function
JS Tutorial
"The above is the detailed content of Examples of how JS calls PHP and PHP calls JS. For more information, please follow other related articles on the PHP Chinese website!