简体   繁体   English

如何在Javascript中让等1的方法完成其他

[英]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.

相关问题 如何在不使用任何外部API的情况下使javascript函数等待其他函数完成? - How can I make javascript function to wait for other function to finish without using any external APIs? 如何让一个方法等待另一个方法完成? - How can I make a method wait for another method to finish? 如何让function等待其他函数完成后再执行 - How to make function wait for other functions to finish before executing 如何在Javascript中允许异步结果等待其他异步结果完成? - How to allow asynchronous results to wait for other asynchronous results to finish in Javascript? 如何在Javascript中阻止功能并等待其他任务完成 - How to block function and wait for other task to finish in Javascript 如何在返回结果之前等待 javascript 完成所有功能 - how to make wait javascript to finish all functions before return result 如何让程序在继续使用javascript之前等待if语句完成? - How to make the program wait for the if statement to finish before continuing in javascript? 如何在剧作家中等待 JavaScript 完成 - How to wait for JavaScript to finish in playwright 如何在 javascript 中等待 function 完成? - How to wait for function to finish in javascript? 如何等待其他函数以异步方式完成 - How to wait other function finish with async
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM