Home >Backend Development >PHP Tutorial >Two ways of interacting with PHP andjavascript_PHP tutorial

Two ways of interacting with PHP andjavascript_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:01:57892browse

During the web production process, how to maintain interaction between the front page and the
background CGI page without refreshing the page has always been a problem. Here are two methods I use in practice
.

Method 1: Interaction through Cookie. There are three files in total, namely:
index.htm, action.php, main.htm
The principle is that the front page main.htm and the background action.php are organized through the page frame
index.htm. Set the page width of action.php to 0, which does not
affect the display. action.php puts information into cookies, and main.htm realizes interaction by reading
cookies. In main.htm, you can also control the background CGI program by re-reading action.php
.

index.htm
----------------------------------------- --------------------------


Test</title> ; <br><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br></head> <br><br><frameset framespacing="0 " border="false" frameborder="0" cols="0,*"> <br> <frame name="leftFrame" scrolling="no" noresize src="action.php"> <br> < ;frame name="rightFrame" scrolling="auto" src="main.htm"> <br></frameset><noframes> <br> <body bgcolor="#FFFFFF"> <br> <p>This page uses page frames, but your browser does not support them. </p> <br> </body> <br></noframes> <br></html> <br>---------------- --------------------------------------------- <br><br>action.php <br>---------------------------------------------- -------------------- <br><? <br>srand((double)microtime()*1000000); <br>$result=rand(0,100 ); <br>setcookie("action",$result,time()+900,"/"); <br>?> <br>---------------- ----------------------------------------------- <br> <br>main.htm <br>----------------------------------------- ----------------------- <br><html> <br><head> <br><title>Test





The current parameter is



Reread Cookie


--------- -------------------------------------------------- ---

Method 2: Interact directly through parent.*.*. There are three files in total, namely:
index.htm, action.php, main.htm, where index.htm is the same as the previous one.
The principle is to directly pass
information through parent.rightFrame.test.current_cookie.value.

action.php
----------------------------------------- --------------------------
srand((double)microtime()*1000000);
$ result=rand(0,100);
?>

----------------------------------------- --------------------------

main.htm
------------- --------------------------------------------------


Test




The current parameter is



Reread Cookie


------------------ ---------------------------------------------

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316734.htmlTechArticleHow to maintain interaction between the front-end page and the background CGI page without refreshing the page during the web page production process has always been a problem question. Here are two methods I use in practice. Fang...
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