Home >Backend Development >PHP Tutorial >How to correctly implement PHP and Javascript interaction_PHP tutorial
We are using
The method of PHP interacting with Javascript: interacting through cookies. 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 pass through the page frame, index. Htm is organized and the page width of action.php is set 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.
Implementation code for interaction between PHP and Javascript:
<ol class="dp-xml"> <li class="alt"><span><span class="tag"><</span><span> </span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></li> <li> <span class="tag"><</span><span> </span><span class="tag-name">head</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">title</span><span class="tag">></span><span>Test</span><span class="tag"><</span><span> /title</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> <br /></span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /head</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">frameset</span><span> </span><span class="attribute">framespacing</span><span>=</span><span class="attribute-value">"0"</span><span> <br /></span><span class="attribute">border</span><span>=</span><span class="attribute-value">"false"</span><span> </span><span class="attribute">frameborder</span><span>=</span><span class="attribute-value">"0"</span><span> </span><span class="attribute">cols</span><span>=</span><span class="attribute-value">"0,*"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"leftFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"no"<br /></span><span> noresize </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"action.php"</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">frame</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">"rightFrame"</span><span> </span><span class="attribute">scrolling</span><span>=</span><span class="attribute-value">"auto"</span><span> <br /></span><span class="attribute">src</span><span>=</span><span class="attribute-value">"main.htm"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /frameset</span><span class="tag">></span><span class="tag"><</span><span> </span><span class="tag-name">noframes</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> </span><span class="tag-name">body</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">"#FFFFFF"</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> </span><span class="tag-name">p</span><span class="tag">></span><span>本页使用页面框架,但是您的浏览器不支持。</span><span class="tag"><</span><span> /p</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> /body</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> /noframes</span><span class="tag">></span><span> </span> </li> <li> <span class="tag"><</span><span> /html</span><span class="tag">></span><span> </span> </li> <li class="alt"> <span class="tag"><</span><span> ? </span></li><li><span>srand((double)microtime()*1000000); </span></li><li class="alt"><span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">rand</span><span>(0,100); </span></li><li><span>setcookie("action",$result,time() 900,"/"); </span></li><li class="alt"><span class="tag">?></span><span> </span> </li> </ol>
The above is the specific implementation method for interaction between PHP and Javascript.