简体   繁体   中英

which one is executed first

I have a web application in php, I don't know which one will be ever called an processed first,

In my php file, I also have a javascript code

<script> $(document).ready(function(){}); </script>

In my php code, I will send an array object into that javascript. So I wonder why the php code is executed first instead of the javascript ? Does it mean that all server code will always be executed before the client script runs during the browser view is shown.

首先执行服务器端代码,并将服务器端生成的输出发送回执行客户端代码的客户端。

Yes, normally, the whole server processing finished before the page is delivered to the browser. At this moment, JavaScript execution starts.

You can add late execution of PHP code using AJAX.

当然,服务器代码(无论是PHP,ASP,JSP等)首先在服务器中运行,它生成一个包含您的javascript代码的html页面,您的计算机接收此页面,在浏览器中呈现它并运行javascript in它。

if you have html,php,js in a single file you should know these two things only:

1)your file extension must be .php (because php execution required .php extension)

2)you will see the output exactly in the same order as you typed in your file.

<html>
<body>
<?php
 echo "i m php upper"."</br>";
?>
<p id="pg">i am html upper</br></p>
<script type="text/javascript">
document.write(" i am javascript upper</br>");
</script>
<?php
 echo "i m php bottem"."</br>";
?>
<script type="text/javascript">
document.write(" i am javascript bottom</br>");
</script>
<p id="pg">i am html bottem</br></p>
</body>
</html>

im php upper

i am html upper

i am javascript upper

im php bottem

i am javascript bottom

i am html bottem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM