[英]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. 在asp.net网站上,我需要提交一些字段以插入数据库。 OnclientClick event i have javascript method to validate the input, it method return false in case validation failed and true in case validation success.
OnclientClick事件我有一个javascript方法来验证输入,如果验证失败,则该方法返回false;如果验证成功,则该方法返回true。 If it return true then server side event process ahead to insert the data.
如果返回true,则服务器端事件处理将提前插入数据。
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. 我的问题是在javascript主要验证方法中,它通过ajax调用服务器端方法来获取一些数据以验证表单。 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.
主要的javascript方法不要等待服务器端调用,它会继续进行处理,这意味着我无法验证该方法,因此会进行回发。
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. 换句话说,我需要实现逻辑,以便1个javascript方法应等待完成另一个javascript的调用。
Your javascript function calls AJAX to validate the data and every AJAX call complete then it will return value. 您的javascript函数调用AJAX来验证数据,并且每个AJAX调用完成后,它将返回值。 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.
因此,您需要做的是,从AJAX调用返回一些值,如果该值为true,则可以在调用服务器大小单击事件之后。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.