【问题标题】:Thymeleaf Jquery Syntax ErrorThymeleaf Jquery 语法错误
【发布时间】:2016-11-11 11:42:21
【问题描述】:

我使用 Thymeleaf 作为视图引擎。

Jquery 脚本引发语法错误。

请注意,我没有在此处发布控制器,因为它运行良好。

这里是代码

<!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>

这是错误,

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

【问题讨论】:

  • 这是一个非常基本的语法错误,你可能需要做一些关于javascript调试的基础教程。

标签: javascript jquery spring-boot thymeleaf


【解决方案1】:

您需要混合引用类型。用单引号替换内部的,使其成为单个字符串

“这是'正确'的答案”

【讨论】:

  • 写成,url: ""
猜你喜欢
  • 1970-01-01
  • 2013-05-19
  • 2013-05-23
  • 2010-12-22
  • 2015-05-07
  • 2012-09-09
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多