开发者

How to ask javascript wait for mysql assign value to php variable?

开发者 https://www.devze.com 2023-03-12 13:59 出处:网络
开发者_开发百科<?php $query3 = \"SELECT message FROM messageslive LIMIT 1\"; $result3 = mysql_query($query3,$connection) or die (mysql_error());
开发者_开发百科<?php
  $query3 = "SELECT message FROM messageslive LIMIT 1";
  $result3 = mysql_query($query3,$connection) or die (mysql_error());
  confirm_query($result3);
  while($userinfo3 = mysql_fetch_array($result3)){
      $msgLive = $userinfo3['message'];
  }
?>

<script type="text/javascript">
  var msg = "<?php echo $msgLive ; ?>";
</script>

What I worry is when the database table has too many data to search and retrieve, so PHP variable $msgLive doesn't have value yet, so Javascript variable var msg get empty value. How to ask javascript wait until PHP variable $msgLive got the value then only transfer the value from php variable to Javascript?


You shouldn't worry about this because first the server script executes, takes its time to communicate with the database, assigns the msgLive variable a value, and finally it generates the HTML which is sent to the client. During all this time the client waits (and probably curses his ISP for the slow connection he is experiencing :-)). So once the HTML reaches the client browser the javascript variable will have its value set. So no need to tell javascript to wait, javascript doesn't even exist until the server finishes its job and pushes the HTML to client.

0

精彩评论

暂无评论...
验证码 换一张
取 消