Home  >  Article  >  Backend Development  >  Introduction to transferring values ​​between js and php_PHP tutorial

Introduction to transferring values ​​between js and php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:03:22821browse

JS is the language of the front-end, and PHP is the language of the back-end. When I first started learning, I often couldn’t distinguish between the front-end and the back-end (I was like this at the beginning, and I still do it sometimes now). My original idea was to treat the front-end and back-end as two Islands cannot be crossed. HTML is like a bridge. When you want to transfer variables from one island to another, you can only use this bridge.
Let me make a small summary:
1: How to transfer the value in HTML to JS. The following assumes that it is file 1.php

Copy code The code is as follows:


>
">
                   < /html>


JS If you want to get the name value entered by the user in the text box, write like this


Copy code

The code is as follows:



In this case, an alert box will pop up when JS get() is called, and the content inside is the value of name.

2: If the name value obtained in JS is to be returned to the rename text box, write like this


Copy code
The code is as follows:



In this case, calling get() below will automatically show you The value entered in name above.

3: Get the value of the page in PHP
I think everyone knows this


Copy the code

The code is as follows:
$name=$_REQUEST["username"];echo $name;
?>



4: PHP value is returned to the page

Insert PHP language into HTML, you can call the value of the variable in PHP, or you can use Smarty (recommended).
With the above, whether it is the value in the HTML page or the value of the variable in JS, it can be easily passed into PHP. Of course, the value of PHP can also be passed to the desired place.

http://www.bkjia.com/PHPjc/327851.html
www.bkjia.com

truehttp: //www.bkjia.com/PHPjc/327851.htmlTechArticleJS is the language of the front-end, and PHP is the language of the back-end. When you first learn, it is often difficult to distinguish between the front-end and the back-end. (I was like this at the beginning, and I still do it sometimes now). My original idea was to put my ex...
Statement:
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
Previous article:Introduction to 21 ways to improve PHP performance_PHP TutorialNext article:Introduction to 21 ways to improve PHP performance_PHP Tutorial

Related articles

See more