[英]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? 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? Thankyou谢谢
$('#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: 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);
}
Service method:服务方式:
@Override
public String findByEmailAndMobile(String email, String mobile) {
Customer customer = repository.findByEmailAndMobile(email,mobile);
return (customer == null)? "Unique" : "Duplicate";
}
Use this with class attribute.将此与 class 属性一起使用。 Multiple id will not work with the version you are using it seems.多个 id 似乎不适用于您正在使用的版本。
for ex:-例如:-
$(document).ready(function(){ $(".test").change(function(){ Your code and use change method. Do not use blur. }); }); $(document).ready(function(){ $(".test").change(function(){ 你的代码和使用change方法。不要使用blur。}); });
HTML=> HTML=>
It will work.它会起作用的。 Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.