简体   繁体   English

php内的HTML,包括javascript

[英]Html inside php, including javascript

I am trying to do following things: 我正在尝试做以下事情:

in my index.php I have: 在我的index.php中,我有:

$GLOBALS['MAINURL'] = "http://localhost/myapp/";

in the function in which I am generating the page header: 在生成页面标题的函数中:

public function header() {
     echo"<!DOCTYPE html>
     <html lang='en'>
     <head>
        <meta charset='utf-8'>
        <meta http-equiv='X-UA-Compatible' content='IE=edge'>
        <meta name='viewport' content='width=device-width, initial-scale=1'>

        <!-- Bootstrap themes stuff here -->

        <title>My app title</title>    

        <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
        <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js'></script>
        <script type='text/javascript' src='" . $GLOBALS['MAINURL'] . "Common/main.js'></script>
      </head>
      <body role='document'>";
}

And footer: 和页脚:

public function footer() {
     echo "                
        <footer class='footer'>
            <div class='container'>
                <p class='text-muted'>abc</p>
            </div>
        </footer>

        <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js'></script>
        <script src='". $GLOBALS['MAINURL'] . "Common/js/bootstrap.min.js'></script>
        <script src='". $GLOBALS['MAINURL'] . "Common/js/docs.min.js'> ";   
}

The problem is in concatenating "MAINURL" with the rest of the path for bootstrap.min.js, docs.min.js and main.js (even though they are correct - I echoed them). 问题在于将“ MAINURL”与bootstrap.min.js,docs.min.js和main.js的其余路径连接在一起(即使它们是正确的-我也已将它们呼应)。 When starting the app I have following error in the browser's console: 启动应用程序时,在浏览器的控制台中出现以下错误:

main.js:2 Uncaught SyntaxError: Unexpected token < main.js:2未捕获的SyntaxError:意外令牌<

bootstrap.min.js:2 Uncaught SyntaxError: Unexpected token < bootstrap.min.js:2未捕获的SyntaxError:意外令牌<

docs.min.js:2 Uncaught SyntaxError: Unexpected token < docs.min.js:2未捕获的SyntaxError:意外的令牌<

It doesn't have a problem when I set 我设置的时候没有问题

$GLOBALS['MAINURL'] = "http://localhost/"; 
  • without "myapp/". 没有“ myapp /”。 But then the resources are not found. 但是,然后找不到资源。 Do you have any idea how to deal with it? 您知道如何处理吗? I would rather stay with the directory structure and myapp folder. 我宁愿保留目录结构和myapp文件夹。

close your echo here: 在此处关闭您的回声:

<body role='document'> " // << Needs closure
}

Alsl check your js files. Alsl检查您的js文件。 It appears that they're being openeed but they're just not correctly written, becase jquery.min which you get from google is giving you no problems. 看来他们正在被openeed,但他们只是写得不正确,因为从Google获得的jquery.min不会给您带来任何问题。

I managed to solve it. 我设法解决了。 It turned out my .htaccess file was breaking everything. 原来我的.htaccess文件会破坏所有内容。 Thanks for your hints! 感谢您的提示!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM