Examples of methods for JS to call PHP and PHP to call JS

ringa_lee
Release: 2023-03-15 12:22:02
Original
45887 people have browsed it

JS calls PHP and PHP calls JS. The editor makes the following summary, hoping to help everyone;

First of all: JS method Call the PHP file and get the value inPHP; the following example illustrates:
For example, in the page test_1,is called with the following sentence:

  
Copy after login

test.php file:

Copy after login

When executing thetest.php file, Thetest_1.php file will be called, and the output of the b.php file will be executed as a JS statement,

so here it will A prompt box pops up, 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 files in HTML to call PHP file, the output of the PHP file will be used as JS code by the calling page.
PHPcalls the valueinJS
There is such a piece of code in the test.php page:

 document.write(data)"; ?>
Copy after login

php calls the method (function) in js
It is basically the same as the second case Similarly, use echo scripts to implement JS calls

 test();"; ?>
Copy after login

JS calls PHP variables (1)

  
Copy after login

(2)

 
Copy after login

JS calls PHP function

Copy after login

The above is the detailed content of Examples of methods for JS to call PHP and PHP to call JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!