ajax 下面没有执行,我不明白为什么
below ajax is not executing, I don't understand why
我对 ajax 比较陌生,我正在尝试通过控制器中的响应正文检查移动电子邮件来验证电子邮件和移动设备,但我无法发现我的错误,因为 ajax 语法是新的对我来说,任何人都可以帮助我朝着正确的方向前进吗?谢谢
$('#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);
}
}
});
控制器:
@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 似乎不适用于您正在使用的版本。
例如:-
$(文档).ready(函数(){
$(".test").change(函数(){
您的代码和使用更改方法。不要使用模糊。
});
});
HTML=>
它会起作用的。谢谢!
我对 ajax 比较陌生,我正在尝试通过控制器中的响应正文检查移动电子邮件来验证电子邮件和移动设备,但我无法发现我的错误,因为 ajax 语法是新的对我来说,任何人都可以帮助我朝着正确的方向前进吗?谢谢
$('#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);
}
}
});
控制器:
@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 似乎不适用于您正在使用的版本。
例如:-
$(文档).ready(函数(){ $(".test").change(函数(){ 您的代码和使用更改方法。不要使用模糊。 }); });
HTML=>
它会起作用的。谢谢!