繁体   English   中英

下面 ajax 没有执行,我不明白为什么

[英]below ajax is not executing, I don't understand why

I am relatively new to ajax and I am trying validate email and mobile through response body check mobile email in my controller, I am unable to spot my mistake, since ajax syntax is new to me, can anyone help me out in right direction? 谢谢

$('#email','#mobile').blur(function(){
    alert("in validation");
    var enteredEmail = $("#email").val();
    var enteredMobile = $("#mobile").val();
        $.ajax({
            url : window.location + "checkmobileemail",
            data : {email:enteredEmail , mobile:enteredMobile},
            success : function(result) {
            if (result == 'Duplicate') {
                $("#emailMsg","#mobileMsg").html("Email or Mobile already exists");
                $("#email","#mobile").focus();
                $("#addButton","#saveChanges").prop("disabled",true);
            } else {
                $("#emailMsg","#mobileMsg").html("");
                $().prop("disabled",false);
            }
        }
    });

Controller:

@RequestMapping(value="/checkmobileemail",method= RequestMethod.GET)
@ResponseBody
public String checkMobileEmail(HttpServletRequest req, Model model) {
    String mobile = req.getParameter("mobile");
    String email = req.getParameter("email");
    String id = req.getParameter("id");
    System.err.println("id "+ id + "mobile: "+ mobile + " , email: " + email);
    return service.findByEmailAndMobile(email,mobile);
}

服务方式:

@Override
public String findByEmailAndMobile(String email, String mobile) {
    Customer customer = repository.findByEmailAndMobile(email,mobile);
    return (customer == null)? "Unique" : "Duplicate";
}

将此与 class 属性一起使用。 多个 id 似乎不适用于您正在使用的版本。

例如:-

$(document).ready(function(){ $(".test").change(function(){ 你的代码和使用change方法。不要使用blur。}); });

HTML=>

它会起作用的。 谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM