欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

关于login登录时写了POST还是GET的问题解决

程序员文章站 2022-07-07 23:44:45
thymeleaf/bootstrap 第一行是原来的,错误了,应为submit与下面的ajax冲突了 第二行是修改后,正确的,type改为button

thymeleaf/bootstrap

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

第二行是修改后,正确的,type改为button

<p class="submit">  
    <input type="submit" id="btnLogin" value="登录">  
</p>  
                  
<p class="submit">  
    <input type="button" class="btn btn-default" id="btnLogin" value="登录">  
</p>  

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>