开发者

getting the entire file code on the page while using include/ include_once/ require_once

While开发者_如何学编程 using include / include_once / require_once of the form include 'filename.js';

I get the entire code of the file displaying on the page. What am i doing wrong?


The included file has the text at the global level in the script. If you want the text to only be output on demand then you will need to put it inside a PHP function, and then call that function when appropriate.


You don't include a javascript file within the PHP script. You can embed it within an inline in the page, or more appropriately, you should have the following in your PHP (as part of the HEAD section of your returned page) so the client retrieves the JS file separately:

echo "<script type=\"text/javascript\" language=\"javascript\" src=\"".$js."\"></script>\n";

Where $js is a variable pointing to the script URL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜