0

I have a script in that's code is

       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 {

        }

Here all is working fine but a problem is occurred This ajax calling is call in last. Please suggest what should I do?

Manoj
  • 4,951
  • 2
  • 30
  • 56
  • Do you know how Ajax works? – VJS Jan 06 '15 at 10:20
  • The part where you are checking the isValidate variable should be inside the success part of the Ajax call. – VJS Jan 06 '15 at 10:21
  • The validation code that you added at last should be added as a separate function outside ajax call and you can call it inside success of ajax – user3263194 Jan 06 '15 at 10:22

0 Answers0