程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

ajax 同步不生效

可以用的生效代码

注意 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();
	}
	
	
}

注意位置

赞(0)
未经允许不得转载:程序员一代码搬运工 » ajax 同步不生效
分享到: 更多 (0)