【发布时间】:2018-08-24 10:46:08
【问题描述】:
您好,我有 Spring Boot Web 应用程序,我正在尝试将非常简单的 javascript 脚本添加到我的 index.html 中,该脚本在单击按钮时会重定向到另一个 html。
这是我的 index.html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Dashboard</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.css}" href="../css/bootstrap.css"/>
<link rel="stylesheet" th:href="@{/css/style.css}" href="../css/style.css"/>
</head>
<body>
<div class="container">
<h1 th:inline="text">My Custom CMS Dashboard</h1>
<a href="/addNewPost"><button class="btn btn-primary block"> Add new Post </button></a>
<table class="table posts">
<tr th:each="post : ${posts}" class="post">
<td th:text="${post.title}" class="title"></td>
<td th:text="${post.text}" class="text"></td>
<td th:text="${post.user.username}" class="username"></td>
<td>
<button class="btn block" id="editPostButton" onClick="redirectToEditPost()"> Edit Post </button>
</td>
<td>
<input id="postId" th:text="${post.id}" type="hidden" style="display:none"/>
</td>
</tr>
</table>
</div>
<script type="text/javascript" th:src="@{/webjars/jquery/3.2.1/jquery.min.js/}"></script>
<script type="text/javascript" th:src="@{/js/editPost.js}"></script>
</body>
</html>
这是我的 javascript 文件:editPost.js:
$(document).ready(function () {
function redirectToEditPost(){
window.location = '/editPost/' + $('input#postId').val();
}
}
我不断收到此错误:Uncaught SyntaxError: Invalid or unexpected token
我很确定这是一些奇怪的错误(coughs JavaScript coughs),而不是实际的语法错误,因为我看到了类似的帖子,这些帖子有一些奇怪的问题,比如索引兑现.html 或类似的东西。
谁能帮我解决这个问题,因为我对 JavaScript 错误或调试 JavaScript 或与 JavaScript 相关的任何事情都不是很熟悉
我知道这可能是处理 Spring Boot 配置或 JavaScript 以外的东西,所以我要留下 spring-mvc 标签...
【问题讨论】:
标签: javascript jquery spring spring-mvc