如何正確實現PHP與Javascript互動_PHP教程

來源:互聯網
上載者:User
我們在使用

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互動的實現代碼:

 
  1. < html>
  2. < head>
  3. < title>Test< /title>
  4. < meta http-equiv="Content-Type"
    content="text/html; charset=gb2312">
  5. < /head>
  6. < frameset framespacing="0"
    border="false" frameborder="0" cols="0,*">
  7. < frame name="leftFrame" scrolling="no"
    noresize src="action.php">
  8. < frame name="rightFrame" scrolling="auto"
    src="main.htm">
  9. < /frameset>< noframes>
  10. < body bgcolor="#FFFFFF">
  11. < p>本頁使用頁面架構,但是您的瀏覽器不支援。< /p>
  12. < /body>
  13. < /noframes>
  14. < /html>
  15. < ?
  16. srand((double)microtime()*1000000);
  17. $result=rand(0,100);
  18. setcookie("action",$result,time() 900,"/");
  19. ?>

以上就是PHP與Javascript互動的具體實現方法。


http://www.bkjia.com/PHPjc/446054.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446054.htmlTechArticle我們在使用 PHP與Javascript互動的方法:通過Cookie互動。一共是三個檔案,分別為: index.htm,action.php,main.htm 原理為前台頁面main.htm和後台acti...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.