我對 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";
}
uj5u.com熱心網友回復:
將此與類屬性一起使用。多個 id 似乎不適用于您正在使用的版本。
例如:-
$(document).ready(function(){ $(".test").change(function(){ 你的代碼和使用change方法。不要使用blur。}); });
HTML=>
它會起作用。謝謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/404720.html
標籤:
