Php finishes loading and then only loading javascript. It's true?

Possible duplicate:
How to set javascript to wait for mysql value for php variable?

I heard people say that php codes will be downloaded and then will start loading javascript. Info on How to ask javascript to wait when mysql assigns a value to a php variable?

But when I wrote:

<script type="text/javascript">
alert("<?php echo $username; ?>");
</script>
<?php $username = "abc"; ?>

Cannot warn php variable value. This is because javascript is loaded first, and then php loading starts. Thus, the fact of the server-site script ends up being loaded, but only loading the client site script is wrong?

If javascript can be run before php, I will have a problem with requesting javascript to wait for the mysql value for the php variable. Please help me solve this problem on How to ask javascript to wait when mysql assigns a value to a php variable?

+3
source share
5 answers

PHP runs on the web server, creating an html page (or whatever) that the browser will display. JavaScript is executed on the client side, in the user's browser, so php has, by definition, a ready-made executable file before executing JavaScript.

, , , php , JavaScript . ; , , , JavaScript $username , PHP / ; :

<script type="text/javascript">
alert("<?php echo $username; ?>");
</script>
<?php $username = "abc"; ?>

, :

<script type="text/javascript">
alert("");
</script>

, script, , - , , . :

<?php $username = "abc"; ?>
<script type="text/javascript">
alert("<?php echo $username; ?>");
</script>

php / , set/available alert().

+8

PHP - javascript . . .

+5

PHP Javascript. :

  • -.
  • - PHP script, HTML/Javascript.
  • - HTML/Javascript .
  • HTML Javascript.

, , PHP , Javascript.

+3

, , php- , javascript.

, .

, alert(), , $username ...

PHP script , AJAX.

+1

PHP -. HTML :

<script type="text/javascript">
alert("");
</script>

When it reaches the client side, the variables are no longer set, as you can see.

+1
source

All Articles