WxjMLove 2016-12-19 08:43 采纳率: 0%
浏览 2942

为什么我的Ajax不能跳转到controller

$(function () {
var inpUser = $(".userName");
var inpPsw =$(".psw")
var inpUserVul = inpUser.val();
var inpPswVul = inpPsw.val();
var btn = $(".hs_login_btn");
var tip=$(".hs_login_tip");
var datas=$("form").serialize();
var flagPsw=false;
var flagUser = false;
inpUser.on("keyUp",function(){
if (inpUserVul.trim("") == "") {
tip.html('请输入用户名').fadeIn(500).delay(1500).fadeOut(500);
return false;
}
/* if(!/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/.test(inpUserVul)){
//alert("请输入正确的用户名");
tip.html('请输入正确的用户名').fadeIn(500).delay(1500).fadeOut(500);
return false;
}*/
flagUser = true;
})
inpPsw.on("keyUp",function(){
if (inpPswVul.trim("") == "") {
tip.html('请输入密码').fadeIn(500).delay(1500).fadeOut(500);
return false;
}
/*if(!/^[a-zA-Z]\w{5,15}$/.test(inpPswVul)){
tip.html('请输入正确的密码').fadeIn(500).delay(1500).fadeOut(500);
return false;
}*/
flagPsw=true;
})

btn.on("click",function(){
    $.ajax({
            type: "post",
            url:"/sms/rest/app/user/login",
            data: datas,
            dataType:"json",
            /*beforeSend:function(){

                if (flagPsw == true && flagUser == true) {
                    alert("判断按钮1")
                    return true;
                } else {
                    alert("判断按钮2")
                    tip.html('不符合规则').fadeIn(500).delay(1500).fadeOut(500);
                    return false;
                }
            },*/

            success : function(data) {
               //tip.html('登陆成功').fadeIn(500).delay(1500).fadeOut(500);
                window.location.href="http://localhost:8080/sms/view/register/index.html";
            }/*,
            error: function(request) {
                //alert("失败");
                tip.html('登陆失败').fadeIn(500).delay(1500).fadeOut(500);
            }*/
        }
        );

})

})

@Controller
@RequestMapping("app/user")
public class AppUserController {
@Autowired
private AppUserVOService appUserService;
@RequestMapping("/login")
public @ResponseBody JsonModel loginUser(String cellphonenumber,String userpassword,AppUserVO uv,JsonModel json){
uv.setCellphonenumber(cellphonenumber);
uv.setUserpassword(userpassword);
return appUserService.getUser(uv, json);
}
}
web.xml

<?xml version="1.0" encoding="utf-8"?>
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

<!-- Spring -->
<!-- 配置Spring配置文件路径 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath*:applicationContext.xml
    </param-value>
</context-param>
<!-- 配置Spring上下文监听器 -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring -->

<!-- 配置Spring字符编码过滤器 -->
<filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


<!-- 配置log4j配置文件路径 -->
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
</context-param>
<!-- 60s 检测日志配置 文件变化 -->
<context-param>
    <param-name>log4jRefreshInterval</param-name>
    <param-value>60000</param-value>
</context-param>

<!-- 配置Log4j监听器 -->
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<!-- Spring MVC 核心控制器 DispatcherServlet 配置 -->
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

    <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <!-- 拦截所有/rest/* 的请求,交给DispatcherServlet处理,性能最好 -->
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<!-- 首页 -->
<welcome-file-list>
    <welcome-file>rest/index</welcome-file>
</welcome-file-list>

<!-- 错误页 -->
<error-page>
    <error-code>404</error-code>
    <location>/rest/page/404</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/rest/page/500</location>
</error-page>

  • 写回答

3条回答

  • 不及格_程序猿 2016-12-19 09:16
    关注

    缺少注解 @ResponseBody 加在 @RequestMapping("app/user")下边

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题