Maison > développement back-end > tutoriel php > 如何正确实现PHP与Javascript交互_PHP教程

如何正确实现PHP与Javascript交互_PHP教程

WBOY
Libérer: 2016-07-15 13:33:26
original
866 Les gens l'ont consulté

我们在使用

PHP与Javascript交互的方法:通过Cookie交互。一共是三个文件,分别为:

index.htm,action.php,main.htm

原理为前台页面main.htm和后台action.php通过页面框架,index.htm组织起来,将action.php的页面宽度设为0,这样并不影响显示。action.php将信息放入cookie中,main.htm通过读取
cookie来实现交互。在main.htm中也可以通过重新读取action.php来实现控制后台CGI程序。

PHP与Javascript交互的实现代码:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> </span><span class="tag-name">html</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> </span><span class="tag-name">head</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">title</span><span class="tag">></span><span>Test</span><span class="tag"><span> /title</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><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></span></li>
<li class="alt"><span class="tag"><span> /head</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><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></span></li>
<li class="alt"><span class="tag"><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></span></li>
<li><span class="tag"><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></span></li>
<li class="alt"><span class="tag"><span> /frameset</span><span class="tag">></span><span class="tag"><span> </span><span class="tag-name">noframes</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><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></span></li>
<li class="alt"><span class="tag"><span> </span><span class="tag-name">p</span><span class="tag">></span><span>本页使用页面框架,但是您的浏览器不支持。</span><span class="tag"><span> /p</span><span class="tag">></span><span> </span></span></span></li>
<li><span class="tag"><span> /body</span><span class="tag">></span><span> </span></span></li>
<li class="alt"><span class="tag"><span> /noframes</span><span class="tag">></span><span> </span></span></li>
<li><span class="tag"><span> /html</span><span class="tag">></span><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>
Copier après la connexion

以上就是PHP与Javascript交互的具体实现方法。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446054.htmlTechArticle我们在使用 PHP与Javascript交互的方法:通过Cookie交互。一共是三个文件,分别为: index.htm,action.php,main.htm 原理为前台页面main.htm和后台acti...
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal