0

How can I wait for complete execution of a function and then call another function like

<script src="whereMyfunctionIs.js"></script>
<script>
 $(window).ready(start());
 function start (){
 myfunction().WhenFunctionDone(myOtherFunction());
 }
</script>

I wanna know if there is a method(js or jQuery) that can wait til myfunction completes, I've already used done, ready and load, an it doesn't wait.

Error messages:

jQuery.Deferred exception: Cannot read property 'ready' of undefined

jQuery.Deferred exception: Cannot read property 'load' of undefined

jQuery.Deferred exception: Cannot read property 'done' of undefined

CDspace
2,69919 gold badges32 silver badges39 bronze badges
asked May 23, 2017 at 22:08
1

1 Answer 1

1

Try this:

<script>
$(window).ready(start());
function start (){
 $.when(myfunction()).done(myOtherFunction);
}
</script>

Here is the documentation for $.when.

Here is an explanation of Javascript's synchronous vs asynchronous execution.

Here is a similar question to yours.

answered May 23, 2017 at 22:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.