0

問題があり、解決策が必要です。データベースに変更があるたびにdividに更新されるサーバー送信イベントがあります。ここで私の質問は、そのdiv idから値を取得し、それをPHP変数に保存する方法です。

<script>
    if(typeof(EventSource)!=="undefined")
    {
        var source=new EventSource("bookcounterevent.php");
        source.onmessage=function(event)
        {
            document.getElementById("bookcounter").innerHTML=event.data;
        };
    }
    else
    {
    document.getElementById("bookcounter").innerHTML="Please update your browser!!";
    }
    </script>
    <div id="bookcounter"></div>

上記のコードは更新します。idbookcounter<div id="bookcounter"></div>で受け取った値が必要です。これをphp変数に保存します。どうすればそれができますか?$book

前もって感謝します。

4

1 に答える 1

1
<style>
#notification {
    color:green;
}
#nonotification {
    color:red;
}
</style>
<script> 
      if(typeof(EventSource)!=="undefined") 
      { 
          var source=new EventSource("bookcounterevent.php"); 

          source.onmessage=function(event) 
          { 
              if(parseInt(event.data) > 0){ 
                document.getElementById("bookcounter").innerHTML=event.data; 
              } 
              else{ 
                document.getElementById("nonotification").innerHTML= 'nothing to display'; 
              } 
          }
      } 
      else 
      { 
        document.getElementById("bookcounter").innerHTML="Please update your browser!!"; 
      } 
  </script>

<div id="notification"></div>
<div id="nonotification"></div>
于 2012-11-02T01:04:38.973 に答える