为什么ajax在函数结束时调用

时间:2015-01-06 10:18:50

标签: javascript jquery ajax

我的脚本代码是

       var isValidate = false;
        $.ajax({
            url: '/Assessment/ValidDischargeDate',
            data: { EpisodePeriodFrom: $('#EpisodePeriodFrom').val(), DischargeOrderDateTime: $('#DischargeOrderDateTime').val() },
            type: 'post',
            success: function (data) {
                console.log('before ' + isValidate); // this show in last
                if (data != true) {
                    alert(data);
                    isValidate = false;
                    return false;
                }
                else {
                    isValidate = true;
                }
            }
        });
        console.log('after '+isValidate); // this show at first
        if (isValidate == true) {
// I want something here but this never call because it call in starting I want this should be called after ajax calling.
        }
       else {

        }

这里一切正常但发生了问题这个ajax调用是最后一次调用。 请建议我该怎么做?

0 个答案:

没有答案