Thymeleaf Jquery语法错误

时间:2016-07-08 20:01:41

标签: javascript jquery spring-boot thymeleaf

我使用Thymeleaf作为视图引擎。

Jquery Script会引发语法错误。

请注意,我没有在这里发布控制器,因为它运作良好。

这是代码

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Add Author</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../public/bootstrap-3.3.6-dist/css/bootstrap.css" th:href="@{/bootstrap-3.3.6-dist/css/bootstrap.css}"/>
<script src="../public/jquery/jquery-3.0.0.min.js" th:src="@{/jquery/jquery-3.0.0.min.js}"></script>


</head>
<body>
<h1>Add New Author</h1>
<div class="col-lg-3" >
<form class="addAuthorForm" role="form" action="#" th:action="@{/author/new-author}" th:object="${addNewAuthor}" method="post">

<div th:class="form-group" th:classappend="${#fields.hasErrors('phone')}? 'has-error'">
    <label>Phone</label>
    <input class="form-control" type="text" th:field="*{phone}" placeholder="Enter author's phone number"/>
    <p th:if="${#fields.hasErrors('phone')}" class="label label-danger" th:errors="*{phone}">Phone Error</p>
</div>

<button type="submit" class="btn btn-default">Add</button>
<button type="reset" class="btn btn-default">Reset</button>

</form>
</div>

<script type="text/javascript">
$(document).ready(function() {

    $(".addAuthorForm").validate(
            {
                rules: {
                    name: {
                        required : true,
                        remote : {
                            url: "<spring:url value='/author/isexist.html'/>",
                            type: "get",
                            data: {
                                phone: function() {
                                    return $("#phone").val();
                                }
                            }
                        }
                    }
                },

                messages: {
                    name: {
                        remote: "Phone number already exists!"
                    }
                }
            }
    );
});
</script>

</body>
</html>

这是错误,

enter image description here

我不明白这里有什么问题。请求指导。

1 个答案:

答案 0 :(得分:1)

您需要混合报价类型。用单引号替换内部的那些,以便它是单个字符串

&#34;这是&#39;权利&#39;答案&#34;