function tjm1(){ var tjm = $("#tjzh"); var tjmid = $("#tjzhId"); if(tjm.val() != ""){ $.ajax({ type : "get", async : false, url:"${pageContext.request.contextPath}/pcUser/checkUserName", data : { "userName" : tjm.val() }, dateType:'html', success : function(data) { if (data == "0") { tjmid.className="error_prompt"; tjmid.html("Incorrect input! This user does not exist."); return false;//Can't get } tjmid.className="ok_prompt"; tjmid.html("Correct input! This user exists."); return true;//Can't get } }); } }
-----------------------------******************correct answer** ***************** ---------------------------
function tjm2(){ var tjm = $("#tjzh"); var tjmid = $("#tjzhId"); var flag = false;//declare a variable if(tjm.val() != ""){ $.ajax({ type : "get", async : false, url:"${pageContext.request.contextPath}/pcUser/checkUserName", data : { "userName" : tjm.val() }, dateType:'html', success : function(data) { if (data == "0") { tjmid.className="error_prompt"; tjmid.html("Incorrect input! This user does not exist."); } tjmid.className="ok_prompt"; tjmid.html("Correct input! This user exists."); flag = true;//You can get } }); } return flag; }
function checkForm() { var flagUserName=userNameBlur(); var flagPwd = pwdBlur (); var flagRepwd = repwdBlur (); var flagTel = telBlur (); var flagEmail=emailBlur(); var flagVerificationCode = verificationCodeBlur (); var flagVerificationCheckBox = verificationCheckBox (); var flagtjm1 = tjm1();//Unable to return the boolean value of the function var flagtjm = tjm2();//The boolean value returned by the function can be obtained if(flagVerificationCheckBox==true){ if(flagPwd==true &&flagRepwd==true&&flagTel==true &&flagEmail==true &&flagVerificationCode==true&&flagtjm==true) { return true; } else { alert("Please fill in according to the prompt information!"); return false; } }else{ alert("Please read <<Registration Terms and Privacy Protection>>, if you have read it, please tick!"); return false; } }
The search is always varied, and I always know the results after my own experiments. I still don’t know why this happens, and I can’t get to the bottom of it.