dshmkgq558192365 2018-07-28 21:46
浏览 47

在Go lang中使用模板会出现“未捕获的语法错误”

I'm trying to create a simple server in Go. I have it set up so that it will show me a page when I make a GET request to "/".

func main() {
    http.HandleFunc("/", serveHomePage)
    http.ListenAndServe(":8000", nil)
}

func serveHomePage(w http.ResponseWriter, r *http.Request) {
    homePageTemplate, err := template.ParseFiles("index.html")
    if err == nil {
        homePageTemplate.Execute(w, nil)
    } else {
        panic("Something went wrong with the template!")
    }
}

I have my index.html in the same folder as my server.go file. My directory looks like this:

.
├── index.html
├── scripts
│   ├── jquery.min.js
│   └── main.js
├── server.go
└── styles
    └── main.css

And my index.html has:

<html>
<head>
    <link rel="stylesheet" href="./styles/main.css">
</head>
<body>
    <div class="container">
        <form id="urlSubmitForm">
            <input type="url">
            <button type="submit">Submit URL!</button>
        </form>
    </div>
    <script src="./scripts/jquery.min.js"></script>
    <script src="./scripts/main.js"></script>
</body>
</html>

The error I am getting says,

Uncaught SyntaxError: Unexpected token < on line 1 of my main.js file and line 1 of the jquery.min.js file.

If I click on the error, it points to the first line of my index.html file.

For reference (though I think this isn't relevant), here is my main.js file.

$(document).on("ready", function() {

});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序