WxjMLove
WxjMLove
采纳率0%
2016-12-19 08:43 阅读 2.7k

为什么我的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条回答 默认 最新

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

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

    点赞 评论 复制链接分享
  • WxjMLove WxjMLove 2016-12-19 09:30

    已经在方法名的返回值哪里加过了

    点赞 评论 复制链接分享
  • tang_cheng tang_cheng 2016-12-20 01:59

    看一下你的spring.xml的配置里有没有:
    <!-- 设定Spring 去哪些包中找Annotation -->

    点赞 评论 复制链接分享

相关推荐