gaohang43
gaohang43
采纳率50%
2015-12-26 04:54 阅读 5.1k

AJAX发送请求,后台接受到数据但是返回结果后,Ajax请求结果失败

10

前台JS和后台相应如下:

 var username = $("#user_name").val().trim();
    var password = $("#password").val();
    console.log(username+","+password);
    $.ajax({
        url:"/Test1224/login.action",
        data:{"username":username,"password":password},
        dataType:"json",
        type:"POST",
        success:function(result){
            console.log("success");
            console.log(result);
        }
    });
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doPost(req, resp);
        System.out.println("enter doPost");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        System.out.println(req.getParameter("username")+","+req.getParameter("password"));
        PrintWriter pw = resp.getWriter();
        Result result = new Result();
        result.setFlag(true);
        result.setName(req.getParameter("username"));
        pw.print(result);
        pw.close();
    }

错误提示:POST http://127.0.0.1:9080/Test1224/login.action 405 (Method Not Allowed)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • u010515202 xhjwyy 2015-12-26 06:57

    换个action名试试 我也发生过这样奇葩的问题 明明后台处理了却没有返回换个action名就好了

    点赞 1 评论 复制链接分享
  • showbo GoCityPass新加坡曼谷通票 2015-12-26 05:38

    /Test1224/login.action这个地址不允许post请求,检查下你的配置

    点赞 评论 复制链接分享
  • qq_19558705 ITDragon龙 2015-12-29 05:27

    你print后立马close会不会有影响。

    点赞 评论 复制链接分享
  • gaohang43 gaohang43 2015-12-30 14:13

    问题已解决,将super.doPost(req, resp);删除掉就好了。进入super.dopost()一下就明白了

    点赞 评论 复制链接分享

相关推荐