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 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区