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

烟雨青岚
烟雨青岚 forward
2020-06-22 13:21:14 2421browse

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:
##

 document.write(data)"; ?>

3. PHP calls methods (functions) in jsIt is basically similar to the second case, using echo scripts to implement JS calls

 test();"; ?>

4. JS calls PHP variable

(1)

  

(2)

 

5. JS calls PHP function


Thank you everyone for reading, I hope you will benefit a lot.

This article is reproduced from: https://blog.csdn.net/wxg694175346/article/details/8592571

Recommended tutorial: "

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete