dsdfd2322 2019-03-30 09:22
浏览 164
已采纳

修复未捕获的语法错误意外令牌<在电子中

I'm testing an electron app that will use php for some business logics. If I run the app from my MAMP stack all will work correctly, but if I run the app using electron, I will recieve an uncaught syntax error unexpected token <that is referenced to the <!DOCTYPE html> of my templates file. I read about this problem here on SO that is related to the path of my js and css files, but I can't figure out how to fix it, this because the paths are correct. I have an header.php file that include all the <head> code and it's required by all the templates files, is the problem caused by this?

header.php file:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="assets/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="assets/css/fontawesome-all.min.css" type="text/css">

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.bundle.min.js"></script>
</head>
<body>

dashboard.php template file:

<?php
require_once 'header.php';
?>
<div class="container">
  <div class="row justify-content-center">

    <div class="col-lg-4">
      <div class="card">
        <div class="card-img-top text-center">
          <i class="fas fa-plus fa-2x"></i>
        </div>
        <a class="btn btn-link" href="add"><h4 class="text-uppercase">add info</h4></a>
      </div>
    </div>

    <div class="col-lg-4">
      <div class="card">
        <div class="card-img-top text-center">
          <i class="fas fa-search fa-2x"></i>
        </div>
      <a class="btn btn-link" href="search"><h4 class="text-uppercase">search info</h4></a>
      </div>
    </div>

  </div>
</div>

</body>
</html>

  • 写回答

1条回答 默认 最新

  • douhao6271 2019-03-30 10:17
    关注

    Your header.php file is a HTML document. Since you require it, it will be interpreted as PHP which causes the syntax error.

    Either create a valid PHP header file or print the contents from the header.php file. I would not recommend the later.

    A simple solution would be:

    1. Rename your header.php to header.tpl (.tpl as in template)
    2. Change you dashboard.php
    <?php
    print file_get_contents('header.tpl'); 
    ?>
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题