可以用的生效代码
注意 boolean 的位置
<script type="text/javascript"> var baseUrl = '${pageContext.request.contextPath }'; function formcheck(){ var flag = false; var customerName='aa'; var country='aa'; var city='beijing'; $.ajax({ type: 'POST', url:baseUrl + "/exports/credit/findBuyersBySerach", data:{"customerName":customerName,"country":country,"city":city} , dataType:"json", async: false, success: function(json){ if(json.code == '0') { layer.msg(json.message+"true"); flag = true; }else{ layer.msg(json.message); flag= false; } } }); return flag; } function submitForm(){ var result = formcheck(); alert(result); if ( result == true) { $("#CreditAmountForm").submit(); } } </script>
不生效的代码
var baseUrl = '${pageContext.request.contextPath }'; function formcheck(){ var customerName='aa'; var country='aa'; var city='beijing'; $.ajax({ type: 'POST', url:baseUrl + "/exports/credit/findBuyersBySerach", data:{"customerName":customerName,"country":country,"city":city} , dataType:"json", async: false, success: function(json){ if(json.code == '0') { layer.msg(json.message+"true"); return true; }else{ layer.msg(json.message); return false; } } }); return false; } function submitForm(){ var result = formcheck(); alert(result); if ( result == true) { $("#CreditAmountForm").submit(); } }
注意位置