When php is used as javascript, chrome interprets the file content as html. our website advertisement uses php to dynamically generate javascript scripts, and directly uses the php file as a javascript file, on the home page, there is usually such code & lt; script & nbsp; src = 'XXX/ad_j. When PHP is used as javascript, chrome interprets the file content as html.
The advertisement on our company's website uses php to dynamically generate javascript scripts and directly use the php file as a javascript file. such code is usually found on the home page.
《script》
This ad_js.php only has such a statement.
No exception occurred when explaining the file for all other browsing operations, but chrome interpreted it as html. that is to say, only a bunch of comments are left in ad_js.php.
When I open the chrome debugger, the following warning appears:
Has anyone ever encountered such a situation?
Currently, my solution is to directly echo the js code, but I want to maintain the original method.
Do you have a good solution?
------ Solution --------------------
Although you don't want to use it, you still need to use echo.
------ Solution --------------------
Can I add type = "text/javascript "?
------ Solution --------------------
The PHP file must declare the type before output.
header('Content-Type: application/javascript');
Otherwise, it is declared as text/html by default, and should be parsed as html format
------ Solution --------------------
As the script tag source, it must be interpreted as html?
The current world is too bad, and simple things must be so complicated. Miss the world dominated by Microsoft
Style sheets require text/css
Js requires application/x-javascript
All returned files must have corresponding header descriptions.