0

Note : No jQuery

I have four functions and I want to call them one after another ie. call a function after the previously called function is executed (in core js, not jquery). I tried searching in the internet but I could not find a satisfied answer. Here is what I've done so far :

function func1() { noAjaxCall.click(); return true; } function func2() { ajaxCall.click(); <--------- sending an ajax request return true; } function func3() { noAjaxCall.click(); return true; } function func4() { //anything here } if(func1()) if(func2()) if(func3()) func4(); 

What happens is that, func3 is not called. Why this happens and any work around to this?

Thanks!

2
  • From just triggering a click, there's not much to wait for, you should call the actual function and return a promise instead of triggering the click, or you could hack it and hook into global ajax events if you're using a library like jQuery. Commented Jan 5, 2014 at 12:39
  • yeahm I noticed that; and I'm not using jQuery here! Commented Jan 5, 2014 at 12:40

1 Answer 1

1

I'm sure you're not doing what you expect. The AjaxCall is not really done when func3 will be called, cause... it's asynchronous.

I prefere you find the real solution (what you really wanna do) than trying to solve this problem.

Could you give the real goal you try to achieve?

edit

Let's imagime the handle on 'click' for ajaxCall. I know u don't have jQuery on the app but I create what I know.

function requester(){ //do some asyn work $.ajax({ //... success: function() { //HERE call the other functions } }); } 
Sign up to request clarification or add additional context in comments.

2 Comments

ok, asking the work around is beyond the scope of the original question! Thanks :)
I've edited but you should read about asynchronous callback in JS :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.