Running Javascript in PHP
Posted
by
Zero
on Stack Overflow
See other posts from Stack Overflow
or by Zero
Published on 2010-12-31T10:45:58Z
Indexed on
2010/12/31
10:53 UTC
Read the original article
Hit count: 193
I'm loading an external .php file using:
<script type="text/javascript" src="myfile.js.php"></script>
Within the external myfile.js.php file, I'm using:
<?php
header('content-type: text/javascript');
$message = "Test message";
?>
document.write('<?php echo $message; ?>');
Everything works fine until I change the name of myfile.js.php to just myfile.php
Why does it stop working if I remove the .js part from the file name? I'm serving the file as text/javascript, plus shouldn't the .js part be ignored since .php is the actual file extension?
Does anyone know why?
Thanks!
© Stack Overflow or respective owner