修复未捕获的语法错误意外令牌<在电子中 [英] Fix Uncaught syntax error unexpected token < in electron

查看:84
本文介绍了修复未捕获的语法错误意外令牌<在电子中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个电子应用程序,该应用程序将使用php来实现某些业务逻辑。如果我从MAMP堆栈中运行该应用程序,则所有程序都将正常运行,但是,如果我使用电子程序运行该应用程序,则将收到一个 uncaught语法错误,意外令牌< 到我的模板文件的<!DOCTYPE html> 。我在SO上阅读了与我的js和css文件的路径有关的此问题,但由于路径正确,因此我无法弄清楚如何解决该问题。我有一个header.php文件,其中包含所有< head> 代码,并且所有模板文件都需要它,这是由问题引起的吗?

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文件:

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模板文件:

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>


推荐答案

您的header.php文件是HTML文档。既然您需要它,它将被解释为PHP,这会导致语法错误。

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

要么创建一个有效的PHP头文件,要么打印header.php文件中的内容。我不推荐后者。

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. 将您的header.php重命名为header.tpl(如模板中的.tpl)

  2. 更改您的dashboard.php



<?php
print file_get_contents('header.tpl'); 
?>
...

这篇关于修复未捕获的语法错误意外令牌&lt;在电子中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆