其他分享
首页 > 其他分享> > Spring MVC Login Demo1

Spring MVC Login Demo1

作者:互联网

加上上一篇拦截器文章代码综合一下
<body>
<div>
<input type="hidden" id="txtHiddenCtx" value="${pageContext.request.contextPath}" />
用户名:<input type="text" id="txtuserid"/><br>
密码:<input type="password" id="txtpassword"/>
<input type="button" value="登录" onclick="loginc();"/>
</div>
<script type="text/javascript">
var ctx = $("#txtHiddenCtx").val();
function loginc() {
var paramData = new Object();
paramData.userid = $("#txtuserid").val();
paramData.password = $("#txtpassword").val();

    var jsonData = JSON.stringify(paramData);

    $.ajax({
        url : ctx + "/auth/loginc",
        type : "POST",
        async : true,
        // contentType:"application/x-www-form-urlencoded",
        contentType : "application/json;charset=utf-8",
        dataType : "json",
        data : jsonData,
        beforeSend : function(XMLHttpRequest) {
        },
        success : function(data, textStatus) {
            if(data.flag == 1){
                window.location.href = ctx + "/";
            }else{
                alert(data.msg);
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            // 通常情况下textStatus 和errorThown只有其中一个有值

            alert("error: " + XMLHttpRequest.responseText);

        },
        complete : function(XMLHttpRequest, textStatus) {
        }
    });

}

/script>

标签:function,textStatus,XMLHttpRequest,val,Spring,paramData,MVC,Login,data
来源: https://blog.51cto.com/6000734/2359975