简体   繁体   中英

PHP echo with Javascript syntax?

Ok, Apologies because this is a kind of a repeat of some previous questions but somehow those aren't getting my any closer to an answer. I have a while loop in PHP where I'm trying to update the contents of a div using Java script and I think I must be messing up the syntax somehow because I'm not getting any output. Here's the code:

 echo '<script language="javascript">document.getElementById("information").innerHTML = "' . $num . ' files processed.";</script>';

Am I missing something here syntax wise? I feel like I must be because I can echo out just $num and get the correct values. Thanks in advance!

You can do it from javascript side. Just write a simple script in your php file

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

    document.getElementById("information").innerText = num + "file proceed";
</script> 

The output is likely cached on the server side. Use flush() after each echo, turn off any output buffering, gzip compression in webserver. You might also try to output white characters to fill the buffers. And inspect what you get in firebug.

跳出/ in </script>

echo '<script language="javascript">document.getElementById("information").innerHTML = "' . $num . ' files processed.";<\/script>';

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