简体   繁体   中英

How to make wait the 1 method to finish other in Javascript

In asp.net website, i need to submit the some fields to insert into database. OnclientClick event i have javascript method to validate the input, it method return false in case validation failed and true in case validation success. If it return true then server side event process ahead to insert the data.

My problem is in javascript main validation method it call server side method through ajax to get some data in order to validate the form. Main javascript method dont wait of server side call and it process move ahead, that means i am not able to validate that method and it go ahead and make postback.

function ValidateInput()
{
if(1 == 2)
{
return false;
}
// other logic to validate
ServiceSideCalltoValidate();
// It dont wait of above method and make the postback
}

In other words i need to implement the logic so that 1 javascript method should wait to finish the call of another javascript.

Your javascript function calls AJAX to validate the data and every AJAX call complete then it will return value. So what you need to do it, return some value from AJAX call and if its true then after you can call server size click event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM