function CheckAdd() {
var flag = true;
$.ajax({
cache: false,
async: false,
url: "/ajaxpage/getajax.aspx?t=adjserviceclientlist&Cellphone=" + Cellphone + "&a=" + Math.random(),
dataType: 'json',
success: function (data) {
if (data != null) {
var result = data["Remark"];
if (result == '此号码已经存在而且已经绑定了主号,不能再次绑定!') {
alert(result);
flag = false;
}
if (result == '此号码已经存在,确定要绑定到主号上吗?') {
if (confirm('此号码已经存在。确定要绑定到主号上吗?')) {
$('#MainContent_Hiddend_IsExitCellPhone').val('1');
} else {
flag = false;
}
}
}
}
})
if (!flag) {
return false;
}
}



<asp:Button ID="Button4" runat="server" Text="提  交"  OnClick="btnAddCustomer_Click" OnClientClick="return CheckAdd();" />



问题一:ajax默觉得异步运行,所以,当运行ajax时,事实上也在运行后台方法了。

如:

async: false即为同步了。



问题二:ajax请求返回的数据里,进行推断,不能直接进行 return false操作。须要赋值,请求方法外运行。如:

if (!flag) {
        return false;
    }