thymeleaf/bootstrap




html

第一行是原来的,错误了,应为submit与下面的ajax冲突了

第二行是修改后,正确的,type改为button
<div class="submit">     <input type="submit" id="btnLogin" value="登录"> </div>
<div class="submit">     <input type="button" class="btn btn-default"
id="btnLogin" value="登录"> </div>
js
<script> $('#btnLogin').on('click', function () { $.ajax({ url: "/toLogin",
type: "POST", dataType: "json", data: $('#myLogin').serialize(), cache: false,
success: function (data) { if (data.code == "1" && data.msg == 'success') {
window.location.href="/index"; setTimeout(function(){
location.replace('/index'); }, 1000); } }, error: function (data) {
window.alert('登陆失败'); window.location.href="/login"; }, complete: function () {
} }); }); </script>