qq_37950073 2021-09-29 09:48 采纳率: 33.3%
浏览 78
已结题

Ajax+SSM请求成功,返回值为空进入erro,这样一来数据库找不到这个账号和密码岂不是也会进入erro,实际上需要进入success再做判断。

IDEA后台执行日志
DEBUG [http-nio-8080-exec-8] - PooledDataSource forcefully closed/removed all connections.
DEBUG [http-nio-8080-exec-8] - Opening JDBC Connection
DEBUG [http-nio-8080-exec-8] - Created connection 1075980333.
DEBUG [http-nio-8080-exec-8] - Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - ==> Preparing: select * from users where userName = ? and userPassword = ?
DEBUG [http-nio-8080-exec-8] - ==> Parameters: addd(String), G@@(String)
DEBUG [http-nio-8080-exec-8] - <== Total: 0
绯荤粺寮傚父
close database
DEBUG [http-nio-8080-exec-8] - Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@4022282d]
DEBUG [http-nio-8080-exec-8] - Returned connection 1075980333 to pool.
database is closed
select resultnull
DEBUG [http-nio-8080-exec-8] - Using 'application/json', given [application/json, text/javascript, /;q=0.01] and supported [application/json, application/*+json]
DEBUG [http-nio-8080-exec-8] - Nothing to write: null body
DEBUG [http-nio-8080-exec-8] - Completed 200 OK

浏览器控制台日志

{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ (e)
always: ƒ ()
complete: ƒ ()
done: ƒ ()
error: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ (e)
overrideMimeType: ƒ (e)
pipe: ƒ ()
progress: ƒ ()
promise: ƒ (e)
readyState: 4
responseText: ""
setRequestHeader: ƒ (e,t)
state: ƒ ()
status: 200
statusCode: ƒ (e)
statusText: "parsererror"
success: ƒ ()
then: ƒ ()
[[Prototype]]: Object

Ajax请求代码

function admin_login(){
    var username = $.trim($("#username").val());
    var password = $.trim($("#userpassword").val());
    if(username === ""){
        alert("请输入用户名");
        return false;
    }else if(password === ""){
        alert("请输入密码");
        return false;
    }
    //开始传递到后端校验
    var data= {userName:username,userPassword:password};//userName、userPassword必须与后端的接收变量名一致

    $.ajax({
        type:"POST",
        url:'dologin',
        data:data,
        dataType:'json',
        /*success: onSuccess, //请求成功回调方法
        error: onError      //请求失败回调方法*/
        success:function(data){
            //alert(msg);
            if(data===null){
                window.alert("用户名或密码错误!")
            }
            else{
                window.alert("登录成功"+data.userName)
                console.log(data)
               /* window.location.href = "success"*/
            }
        },
        error:function (data){
            window.alert("服务器连接失败"+data.userName)
            console.log(data)
        }
    });
}

  • 写回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-09-29 09:57
    关注

    你是form表单提交发送异步请求?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月7日
  • 已采纳回答 9月29日
  • 创建了问题 9月29日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改