[英]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.