How does PHP interact with JS?

Source: Internet
Author: User

Today, I suddenly discovered a trick: PHP can pass values to JS. How can this problem be solved?

 

The principle of PHP is as follows:

All PHP applicationsProgramAll of them are explained and executed through Web servers (such as IIS or Apache) and PHP engine programs. The work process is as follows:

(1) When you enter the name of the PHP page to be accessed in the browser address, press enter to trigger this PHP request and transmit the request to a Web server that supports PHP.

(2) The Web Server accepts this request and determines based on its suffix that if it is a PHP request, the web server extracts the PHP application to be accessed from the hard disk or memory, and send it to the PHP engine program.

(3)Phpengine Program (php.exe) scans the files sent from the Web server from start to end, reads data from the background, processes data, and dynamically generates the corresponding HTML page according to the command.

(4) The PHP engine returns the generated HTML page to the web server. The Web server then returns the HTML page to the client browser.

So If php wants to pass a value to the html js script, how can it be operated? You can first define the variables you want to use, as shown in the following example:

<? PHP $ test = "Var A =". $ _ Get ['test']. ";";?> <MCE: Script Type = "text/JavaScript"> <! -- <? PHP echo $ test;?> Alert (a); // you can retrieve a here. And the value of A is from the user's GET request // --> </MCE: SCRIPT>

Relevant content will be used in PHP in the future, and JavaScript technology can be easily used to add PHP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.