首页 > 遇到一件怪事,post 请求未等后台相应就拿到了返回值

遇到一件怪事,post 请求未等后台相应就拿到了返回值

遇到一件怪事,在前台发了一个 ajax 请求, 后台断点没走完就有返回值 {},同事也没看出来是什么问题,你们遇到过这种情况吗?

前台

javascript// 当前用户是否QQ登录成功
var isLoginSuc = QC.Login.check();
if (isLoginSuc) {
    // 获取QQ登录的openId
    QC.Login.getMe(function(openId, accessToken){
        // 去数据库查询此 openId 是否绑定用户
        $.post('queryQQ', {"id" : openId}, function(data){
            // ...
        },'json');
    });
}

后台

java    public void queryQQ() {
        OauthApp oauthApp = oauthAppServ.find(id);
        results = new HashMap<String, Object>();
        results.put("isExist", oauthApp != null);
        JSONUtil.responseJSON(results);
        return;
    }

工具类用的阿里的fastjson

javapublic static void responseJSON(Object obj) {
        HttpServletResponse res = ServletActionContext.getResponse();

        res.setContentType("text/html;charset=utf-8");
        res.setCharacterEncoding("utf-8");

        try {
            PrintWriter out = res.getWriter();

            out.write(JSON.toJSONString(obj));
            out.flush();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

在后台调试的时候,断点每走完,前台就接到返回值了。


猜到了开始,没猜到结局啊,手欠在 action 中写了一个名为validate的方法,走了struts默认的校验,直接给返回了

【热门文章】
【热门文章】