i have a question when a .php file called as a javascript what dose this mean? and when this is needed to be used ?
ex:
<head>
<script src="dir/myphpfile.php" type="text/javascript"></script>
</head>
i have a question when a .php file called as a javascript what dose this mean? and when this is needed to be used ?
ex:
<head>
<script src="dir/myphpfile.php" type="text/javascript"></script>
</head>
This means that the myphpfile.php
would generate javascript code as output instead of HTML because that's all that the web browser could understand in a script
tag. It is useful in situations when you want to generate dnyamic javascript at runtime instead of statically coding it in a separate .js
file. Think for example declaring a javascript variable containing the list of customers stored in a database on the server and making this javascript variable globally accessible.
Another common example where this could be useful is to implement JSONP allowing cross domain AJAX requests.
Yet another example is to use a php script that will combine and cache the output of multiple javascript files into one.