Reputation: 1752
In my application i am using asp.net3.5,ajax.dll.
I am calling all functionalities using ajax from javascript.
Sometimes i need to get the condition results from server side, only then i will be able to pass to next condition.
for the above case, javascript passes to next condition before executing the first condition.
So i added the following code to make it work,
setTimeOut("finddefaultvideo()",1000);
.
Can anyone please help me to get rid of this issue?
One thing i understood that,it won't wait for the time until server returns the value.
any idea to overcome the above one?
Upvotes: 0
Views: 209
Reputation: 186742
setTimeout is not reliable for this unless you do some kind of recursive polling technique. You need to invoke finddefaultvideo
after the ajax callback has returned. You could place finddefaultvideo()
inside of your ajax callback, the one that's fired onreadystatechange
and where the readyState is 4 and 'complete'.
ajaxCallback: function(html) {
if ( something ) {
executeRestOfCode();
}
}
function executeRestOfCode() {
// your code that needs to be invoked after the ajax callback
}
Upvotes: 0
Reputation: 38150
I don't know if I understood you correctly but this might be the solution you are looking for (however it is using jquery)
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
the alert message is shown as soon as your ajax request was success full and the server sent response data.
Upvotes: 2